2
$\begingroup$

I can see what I think should be the public key in the Details tab for StackOverflow's certificate (see screenshot below). However, it is 2160 (num of chars (540) multiplied by 4 = 2160) bits long, not 2048 as it specifies.

When I view the certificate details using openssl in cmd, I can see a smaller version of the public key which is 514 nibbles * 4 = 2056 bits, which is one byte off 2048.

I noticed the first byte is 00. Is the first byte to be ignored because it's 0? Why is it displayed in openssl?

If the first byte is to be ignored, does this mean the actual public key starts with b2 and ends in af?

Why does Windows show extra bytes before and after the public key in the Details tab?

I've used Notepad in the screenshot to show the full value of what's in the Details tab.

enter image description here

Update:

I realised the majority of the bytes is the modulus, and the exponent 0x010001 is at the end:

enter image description here

But what is the 02 03 between the modulus and the exponent?

And what is the 30 82 01 0a 02 82 01 01 00 before the modulus?

$\endgroup$
2

1 Answer 1

4
$\begingroup$

As per X.690, the format begins with 0x30 to denote a sequence. Next comes the total length. The first byte of the length is 0x82. Because the highest bit is set here, it means this byte encodes the length of the length. In other words, the next 2 bytes encode the actual length. Those bytes are 0x010a, or 266 bytes.

Now we hit another tag. This time it is 0x02, meaning an integer. The length starts with 0x82 again, so we know the subsequent 2 bytes encode the length. These are 0x0101, so the total length of this integer is 257 bytes. These 257 bytes are the ones you highlighted. The reason the extra 0x00 byte is included in the start is because BER integers are signed and represented in 2's complement - if there was no leading null byte, it would be interpreted as a negative number, since the next byte 0xb2 has the highest bit set.

After those 257 bytes for the modulus, we hit another tag: 0x02 again. Another integer. This time the first byte (0x03) of the length doesn't have the highest bit set, so the length is simply 3 bytes. These 3 bytes are 0x010001, or 65537. That's the public exponent.

And that totals 266 bytes, as expected for the whole sequence. It is just those 2 integers.

$\endgroup$
1
  • 1
    $\begingroup$ I edited the answer to explain why the leading nul byte is there. $\endgroup$
    – DannyNiu
    Feb 4, 2022 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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