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?
'%x' % cert.get_serial_number()
'%x' %
formats string like '{0:x}'.format(cert.get_serial_number())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With