Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

In the public certificate, an RSA public key specified as 2048 bits long is represented by 540 hexadecimal characters. Converted to base-2, this yields 2160 bits, 112 more than the stated 2048.

share|improve this question
    
You'll be surprised if you see the PKCS#1 version of a private key. Normally that one has the modulus, the private exponent, the public exponent and normally all CRT parameters as well. Plus DER overhead of course. And - if used - the overhead of the various container formats. –  owlstead Feb 14 at 14:30
add comment

2 Answers

up vote 6 down vote accepted

That's because the public key in DER format (which is a way of expressing X.509 objects as a sequence of bytes) includes more than just the modulus. Specifically, it consists of:

  • This is a collection of the following objects; that takes up 4 bytes

  • The first object is an integer (which happens to be the public modulus); the integer itself is 257 bytes (not 256; that's because ASN.1 integers are signed, and so there has to be a leading 00 to make the top bit zero to signify positive), as well as 4 overhead bytes, for a total of 261 bytes

  • The second object is an integer (which happens to be the public exponent); if you use 65537 as the exponent, this takes up a total of 5 bytes long (including overhead)

4+261+5 gives you a total of 270 bytes, or 540 hexadecimal characters.

This assumes that the encoder uses an RSA public exponent of 65537 (or some other value between 32769 and 8388607, all of which would encode in the same length); 65537 is by far the most common value nowadays, but is not mandated.

Note that this does not count the encoding that says "this is an RSA public key"; that takes up an additional 24 bytes (including overhead). That's generally included in public keys, but apparently you're not counting that part; that would bring the length past the 540 hex characters you see.

share|improve this answer
    
Minor nit: X.509 objects are always DER encoded and not just BER encoded. DER is a subset of BER, so you might decode any DER encoding with a BER decoder, but the converse is not (necessarily) true, because DER encoding is unequivocal, while BER encoding is not. –  Henrick Hellström Feb 14 at 13:36
    
@HenrickHellström: I was unaware that X.509 used DER, not BER. Thank you for informing me that; I'll fix up my answer accordingly. –  poncho Feb 14 at 13:51
add comment

The standard explains that: the public key contains not only modulus, but also the exponent (usually short) and the algorithm identifier.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.