9

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?

jww
  • 97,681
  • 90
  • 411
  • 885
user1513388
  • 7,165
  • 14
  • 69
  • 111

1 Answers1

5
'%x' % cert.get_serial_number()

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

atn
  • 904
  • 9
  • 17