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.
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.
Share Improve this question edited Jul 30, 2021 at 15:36 Doctor Gonzo asked Jul 30, 2021 at 15:25 Doctor GonzoDoctor Gonzo 331 silver badge5 bronze badges 3-
Could you debug to check the contents of X509Certificate? If you can't debug, use
console.log(JSON.stringify(X509Certificate)); Let's see why it's not a constructor.
– CausingUnderflowsEverywhere Commented Jul 31, 2021 at 4:07 - I tried reproducing myself, and crypto doesn't include X509Certificate so that may be the problem we both have. – CausingUnderflowsEverywhere Commented Jul 31, 2021 at 4:16
-
I'm working with NodeJS version 20.15.1 on ReactJS but still get this issue. console.log(JSON.stringify(X509Certificate)) shown an undefined value. The error I get is:
export 'X509Certificate' (imported as 'X509Certificate') was not found in 'crypto'
– Nathalie Commented Sep 4, 2024 at 4:56
1 Answer
Reset to default 9The 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.