keygen
元素的一部分。<keygen>
is deprecated since HTML 5.2 and new projects should not use this element anymore.
The 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)
spkac
{string | Buffer | TypedArray | DataView}spkac
data structure, which
includes a public key and a challenge.const { Certificate } = require('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])
spkac
{string | Buffer | TypedArray | DataView}encoding
{string} The [encoding][] of the spkac
string.spkac
data structure,
which includes a public key and a challenge.const { Certificate } = require('crypto');
const spkac = getSpkacSomehow();
const publicKey = Certificate.exportPublicKey(spkac);
console.log(publicKey);
// Prints: the public key as <Buffer ...>
Certificate.verifySpkac(spkac)
spkac
{Buffer | TypedArray | DataView}true
if the given spkac
data structure is valid,
false
otherwise.const { Certificate } = require('crypto');
const spkac = getSpkacSomehow();
console.log(Certificate.verifySpkac(Buffer.from(spkac)));
// Prints: true or false
As a still supported legacy interface, it is possible (but not recommended) to
create new instances of the crypto.Certificate
class as illustrated in the
examples below.
new crypto.Certificate()
Instances of the Certificate
class can be created using the new
keyword
or by calling crypto.Certificate()
as a function:
const crypto = require('crypto');
const cert1 = new crypto.Certificate();
const cert2 = crypto.Certificate();
certificate.exportChallenge(spkac)
spkac
{string | Buffer | TypedArray | DataView}spkac
data structure, which
includes a public key and a challenge.const cert = require('crypto').Certificate();
const spkac = getSpkacSomehow();
const challenge = cert.exportChallenge(spkac);
console.log(challenge.toString('utf8'));
// Prints: the challenge as a UTF8 string
certificate.exportPublicKey(spkac)
spkac
{string | Buffer | TypedArray | DataView}spkac
data structure,
which includes a public key and a challenge.const cert = require('crypto').Certificate();
const spkac = getSpkacSomehow();
const publicKey = cert.exportPublicKey(spkac);
console.log(publicKey);
// Prints: the public key as <Buffer ...>
certificate.verifySpkac(spkac)
spkac
{Buffer | TypedArray | DataView}true
if the given spkac
data structure is valid,
false
otherwise.const cert = require('crypto').Certificate();
const spkac = getSpkacSomehow();
console.log(cert.verifySpkac(Buffer.from(spkac)));
// Prints: true or false
Was this page helpful?
很高兴听到! 请告诉我们,我们如何才能改善.
很遗憾听到这个消息。 请告诉我们,我们如何才能改善.