Benito Serna
Ruby, Rails, TDD...

How to read the noCertificado from a CSD for a mexican CFDI

This was new for me, I was looking how to get the noCertificado from a CSD (Certificado de Sello Digital) and I found it is the serial of the certificate but in base 2.

In ruby you can get it with a OpenSSL::X509::Certificate

raw ="my_cert.cer")
cert =

If you ask the serial you will get an OpenSSL::BN

cert.serial # => an OpenSSL::BN

And then you can ask the for the to_s of that object. By default it will return it with base 10

cert.serial.to_s == cert.serial.to_s(10) # => true

…but you can ask for it in base 2, this is the noCertificado =)

cert.serial.to_s(2) # => "noCertificato" value...

Related articles