I'm trying to calculate the size of an RSA public key in Ruby. I've retrieved the key in PEM format, and once I've decoded the base64 part from the PEM format, I get the size in bytes. What I find is that what I retrieve and the actual key size is off by 12 bytes, or 96 bits for that matter – for a 1024 bit key, I get 140 bytes (=1120 bits).
I know there is at least always an exponent and the modulus in the public key. My question is:
Is it always a fixed difference (12 bytes), or can the difference vary and if yes - how do I know how big the difference is?