Search code examples
pythonx509m2crypto

Python x509 get_serial_number() return incorrect value


I'm trying to get the serial number of a x509 with M2cryto the problem is that returns me different values ​​to openssl.

from python

>>> from M2Crypto import X509
>>> cer = X509.load_cert(cerPath, X509.FORMAT_DER)
>>> cer.get_serial_number()
286524172099382162235533054529634765881071645240L

from openssl

openssl x509 -inform DER -in cer.cer -serial -noout
serial=3230303031303030303030323030303031343238

Solution

  • It is a matter of the number format, the number with the decimal presentation

    286524172099382162235533054529634765881071645240
    

    has this hexadecimal presentation

    3230303031303030303030323030303031343238
    

    it's merely a matter of base change.