Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why base64 encode an API authorization key?

We're currently designing a web api and are in the process of implementing authorization. We've followed (mostly) amazons implementation but there's one part I really don't fully understand.

Namely, what is the point of base64 encoding the resulting hmac? The difference in length is negligible, at least for most sites. Amazon would probably notice the difference though. Is that the only reason? Does it maybe have something to do with ascii/unicode?

like image 469
Josh Smeaton Avatar asked Apr 20 '12 11:04

Josh Smeaton


1 Answers

Hash algorithms and HMAC don't provide hexadecimal string outputs, which is what many people tend to believe; they both output binary data. Base64 provides you with a way to easily and portably represent binary data as a string.

As far as why, it's likely just for convenience and using a standard encoding between many different parts of their software. There's nothing special about it, other than it being a widely used encoding.

like image 122
Michael J. Gray Avatar answered Nov 15 '22 23:11

Michael J. Gray