Search code examples
javascriptsecuritycryptographydigital-signaturex509

jsrsasign - how to extract an x.509 certificate's fingerprint?


Is it possible to use jsrsasign to extract the fingerprint of an x.509 certficate, similar to what can be achieved using this openssl command:

openssl x509 -sha1 -in cert.pem -noout -fingerprint - Ref: openssl x.509 doc

I'm reading my X509 like so:

var c = new X509(); c.readCertPEM(cert); \\ how to get the fingerprint?

Ref: jsrsasign x.509 apidoc


Solution

  • You just need to extract the string from between the "-----BEGIN CERTIFICATE-----" header and "-----END CERTIFICATE----- " footer, base64 decode it and compute SHA1 hash of decoded data.