# Why do all SSH-RSA Keys begin with “AAAAB3NzaC1yc”?

My Friend and I have been generating a few ssh2-rsa keys and noticed that all the public keys began with "AAAAB3NzaC1yc". The similarity extended to "AAAAB3NzaC1yc2EAAAABIwAAAQEA" between two keys I generated on the same machine on two successive attempts. I can even google "AAAAB3Nz" and end up getting a few hits.

Is this normal? Or are we doing something wrong while generating? Suffering from insufficient randomness?

-
What are you using to generate them? Openssl, openssh, pgp? It is probably an encoding. –  mikeazo Jan 8 '13 at 17:39
We used puTTYgen on two different windows machine and ssh-keygen on a linux machine. –  Lord Loh. Jan 8 '13 at 18:23

The public key blob doesn't consist of just the numbers that make up the public key: it begins with a header that says “this is an SSH public key”. The repeated prefix encodes this header.

RFC 4254 specifies the encoding of public key in SSH key format.

The "ssh-rsa" key format has the following specific encoding:

 string    "ssh-rsa"
mpint     e
mpint     n


Here the 'e' and 'n' parameters form the signature key blob.

The string is encoded as 32-bit big endian length followed by the literal string:

0,0,0,7,'s','s','h','-','r','s','a'


Encoding this sequence of bytes in Base64 gives:

AAAAB3NzaC1yc2E


The public exponent is also usually the same, so the common prefix is even longer. The bulk of the key is the public modulus, and that is completely different in different keys.

-