Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 596
luis iturrios Avatar asked Oct 27 '25 09:10

luis iturrios


2 Answers

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.

like image 159
mkl Avatar answered Oct 28 '25 23:10

mkl


Thanks. I used it to change number format

>>> '{0:x}'.format(int(cer.get_serial_number()))
3230303031303030303030323030303031343238
like image 44
luis iturrios Avatar answered Oct 28 '25 21:10

luis iturrios



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!