SPKAC is a Certificate Signing Request mechanism originally implemented by
Netscape and was specified formally as part of HTML5's keygen element.
<keygen> is deprecated since HTML 5.2 and new projects
should not use this element anymore.
The node:crypto module provides the Certificate class for working with SPKAC
data. The most common usage is handling output generated by the HTML5
<keygen> element. Node.js uses OpenSSL's SPKAC implementation internally.
Certificate.exportChallenge(spkac, encoding?): Buffer
Attributes
spkac:
string | ArrayBuffer | Buffer | TypedArray | DataViewReturns:
BufferThe challenge component of the
spkac data structure, which
includes a public key and a challenge.const { Certificate } = await import('node:crypto'); const spkac = getSpkacSomehow(); const challenge = Certificate.exportChallenge(spkac); console.log(challenge.toString('utf8')); // Prints: the challenge as a UTF8 string
const { Certificate } = require('node:crypto'); const spkac = getSpkacSomehow(); const challenge = Certificate.exportChallenge(spkac); console.log(challenge.toString('utf8')); // Prints: the challenge as a UTF8 string
Certificate.exportPublicKey(spkac, encoding?): Buffer
Attributes
spkac:
string | ArrayBuffer | Buffer | TypedArray | DataViewReturns:
BufferThe public key component of the
spkac data structure,
which includes a public key and a challenge.const { Certificate } = await import('node:crypto'); const spkac = getSpkacSomehow(); const publicKey = Certificate.exportPublicKey(spkac); console.log(publicKey); // Prints: the public key as <Buffer ...>
const { Certificate } = require('node:crypto'); const spkac = getSpkacSomehow(); const publicKey = Certificate.exportPublicKey(spkac); console.log(publicKey); // Prints: the public key as <Buffer ...>
Certificate.verifySpkac(spkac, encoding?): boolean
Attributes
spkac:
string | ArrayBuffer | Buffer | TypedArray | DataViewReturns:
booleantrue if the given spkac data structure is valid,
false otherwise.import { Buffer } from 'node:buffer'; const { Certificate } = await import('node:crypto'); const spkac = getSpkacSomehow(); console.log(Certificate.verifySpkac(Buffer.from(spkac))); // Prints: true or false
const { Buffer } = require('node:buffer'); const { Certificate } = require('node:crypto'); const spkac = getSpkacSomehow(); console.log(Certificate.verifySpkac(Buffer.from(spkac))); // Prints: true or false
Stability: 0Deprecated
As a legacy interface, it is possible to create new instances of
the crypto.Certificate class as illustrated in the examples below.
new crypto.Certificate(): crypto.Certificate
Instances of the Certificate class can be created using the new keyword
or by calling crypto.Certificate() as a function:
const { Certificate } = await import('node:crypto'); const cert1 = new Certificate(); const cert2 = Certificate();
const { Certificate } = require('node:crypto'); const cert1 = new Certificate(); const cert2 = Certificate();
certificate.exportChallenge(spkac, encoding?): Buffer
Attributes
spkac:
string | ArrayBuffer | Buffer | TypedArray | DataViewReturns:
BufferThe challenge component of the
spkac data structure, which
includes a public key and a challenge.const { Certificate } = await import('node:crypto'); const cert = Certificate(); const spkac = getSpkacSomehow(); const challenge = cert.exportChallenge(spkac); console.log(challenge.toString('utf8')); // Prints: the challenge as a UTF8 string
const { Certificate } = require('node:crypto'); const cert = Certificate(); const spkac = getSpkacSomehow(); const challenge = cert.exportChallenge(spkac); console.log(challenge.toString('utf8')); // Prints: the challenge as a UTF8 string
certificate.exportPublicKey(spkac, encoding?): Buffer
Attributes
spkac:
string | ArrayBuffer | Buffer | TypedArray | DataViewReturns:
BufferThe public key component of the
spkac data structure,
which includes a public key and a challenge.const { Certificate } = await import('node:crypto'); const cert = Certificate(); const spkac = getSpkacSomehow(); const publicKey = cert.exportPublicKey(spkac); console.log(publicKey); // Prints: the public key as <Buffer ...>
const { Certificate } = require('node:crypto'); const cert = Certificate(); const spkac = getSpkacSomehow(); const publicKey = cert.exportPublicKey(spkac); console.log(publicKey); // Prints: the public key as <Buffer ...>
certificate.verifySpkac(spkac, encoding?): boolean
Attributes
spkac:
string | ArrayBuffer | Buffer | TypedArray | DataViewReturns:
booleantrue if the given spkac data structure is valid,
false otherwise.import { Buffer } from 'node:buffer'; const { Certificate } = await import('node:crypto'); const cert = Certificate(); const spkac = getSpkacSomehow(); console.log(cert.verifySpkac(Buffer.from(spkac))); // Prints: true or false
const { Buffer } = require('node:buffer'); const { Certificate } = require('node:crypto'); const cert = Certificate(); const spkac = getSpkacSomehow(); console.log(cert.verifySpkac(Buffer.from(spkac))); // Prints: true or false