Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Google Map Api Key have 39 chars?

Keys always starts from "AIzaSy" (maybe I wrong, but my it's). And next are 33 chars. As I see they using alphabet, numbers and some special chars. It's about 64 variants per char place. And about 64^33 combinations (keys) ~ 401734511064747568885490523085290650630550748445698208825344 keys.

So why they chooses exactly 39 (6+33) chars?

Why not choose 20 chars or 63 chars?

like image 202
Max Lipsky Avatar asked Jan 25 '23 04:01

Max Lipsky


1 Answers

I don't have specific knowledge about how Google Maps API keys are generated, but if you are wondering how this number of characters might make sense from a mathematical point of view, consider this:

Based on observation, a key starts with the 6-character string AIzaSY. If you look closer, you may also find that the 7th character is not completely random. In fact, it seems to often be an upper-case character from the beginning of the alphabet (A, B, C, D...). So this indicates that this character also has some special status, perhaps encoding some additional information. For our purpose, this is not important, but the point is that since this character is clearly not random, it cannot be part of a cryptographically generated key.

So, after this prefix of 7 characters, we have 39 - 7 = 32 characters left. Like you observed, these characters seem to be Base64 encoded. Now, in Base64, each character takes up 6 bits, so we have 32 * 6 = 192 bits (or 24 bytes), which is one of the common standards for the length of keys in cryptography, and provides better security than e.g. 128-bit keys (another standard).

like image 153
Berthur Avatar answered Feb 08 '23 10:02

Berthur