Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X.509 certificate serial number to hex conversion

I'm trying to get the serial number for an X.509 certificate using Pythons OpenSSL library.

If I load my cert like this:

 x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, cert)

Then print the serial number like this:

print x509.get_serial_number()

It looks like this:

5.283978953499081e+37 

If I convert it to hex like this:

'{0:x}'.format(int(5.283978953499081e+37))

It returns this:

27c092c344a6c2000000000000000000

However, using OpenSSL from the command line to print the certificates serial number returns this.

27:c0:92:c3:44:a6:c2:35:29:8f:d9:a2:fb:16:f9:b7

Why is half of the serial number being converted to zeros?

like image 754
user1513388 Avatar asked Sep 02 '16 07:09

user1513388


1 Answers

'%x' % cert.get_serial_number()

'%x' % formats string like '{0:x}'.format(cert.get_serial_number())

like image 108
atn Avatar answered Oct 22 '22 23:10

atn