Doctor Gonzo
Doctor Gonzo

Reputation: 33

Crypto | TypeError: X509Certificate is not a constructor

const { X509Certificate } = require('crypto');

function getCertificateThumbprint(certificate)
{  
  const cert = new X509Certificate(Buffer.from(certificate, 'base64'));
  return cert.fingerprint;
}

I practically copied this code from the crypto documentation code, also this is most likely not a problem with package installations, because crypto is built-in node.js module. Same error, when passing a plain string and not a Buffer.

Upvotes: 3

Views: 3712

Answers (1)

The X509Certificate class was added recently in NodeJS version v15.6.0. Ensure you are using v15.6.0 or newer so that your import works.

Upvotes: 9

Related Questions