Exports
[<Class>]
type Exports =
static member DiffieHellmanGroup: DiffieHellmanGroupConstructor
static member constants: Constants
static member fips: bool
static member generateKeyPair: GenerateKeyPair
static member subtle: SubtleCrypto
static member webcrypto: Crypto
static member Certificate () : Certificate
static member X509Certificate (buffer: BinaryLike) : X509Certificate
static member checkPrime (value: LargeNumberLike, options: CheckPrimeOptions, callback: Callback2) : unit
static member checkPrime (value: LargeNumberLike, callback: Callback) : unit
static member checkPrimeSync (candidate: LargeNumberLike, ?options: CheckPrimeOptions) : bool
static member createCipheriv (algorithm: string, key: CipherKey, ?iv: BinaryLike, ?options: TransformOptions<Transform>) : Cipher
static member createCipheriv (algorithm: string, key: CipherKey, iv: BinaryLike, ?options: CipherChaCha20Poly1305Options) : CipherChaCha20Poly1305
static member createCipheriv (algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike, ?options: CipherGCMOptions) : CipherGCM
static member createCipheriv (algorithm: CipherOCBTypes, key: CipherKey, iv: BinaryLike, options: CipherOCBOptions) : CipherOCB
static member createCipheriv (algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike, options: CipherCCMOptions) : CipherCCM
static member createDecipheriv (algorithm: string, key: CipherKey, ?iv: BinaryLike, ?options: TransformOptions<Transform>) : Decipher
static member createDecipheriv (algorithm: string, key: CipherKey, iv: BinaryLike, ?options: CipherChaCha20Poly1305Options) : DecipherChaCha20Poly1305
static member createDecipheriv (algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike, ?options: CipherGCMOptions) : DecipherGCM
static member createDecipheriv (algorithm: CipherOCBTypes, key: CipherKey, iv: BinaryLike, options: CipherOCBOptions) : DecipherOCB
static member createDecipheriv (algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike, options: CipherCCMOptions) : DecipherCCM
static member createDiffieHellman (prime: string, primeEncoding: BinaryToTextEncoding, generator: string, generatorEncoding: BinaryToTextEncoding) : DiffieHellman
static member createDiffieHellman (prime: string, primeEncoding: BinaryToTextEncoding, ?generator: U14<float,ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : DiffieHellman
static member createDiffieHellman (prime: U13<ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, generator: string, generatorEncoding: BinaryToTextEncoding) : DiffieHellman
static member createDiffieHellman (prime: U13<ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, ?generator: U14<float,ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : DiffieHellman
static member createDiffieHellman (primeLength: float, ?generator: float) : DiffieHellman
static member createDiffieHellmanGroup (name: string) : DiffieHellmanGroup
static member createECDH (curveName: string) : ECDH
static member createHash (algorithm: string, ?options: HashOptions) : Hash
static member createHmac (algorithm: string, key: CipherKey, ?options: TransformOptions<Transform>) : Hmac
static member createPrivateKey (key: U4<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,JsonWebKeyInput,PrivateKeyInput>) : KeyObject
static member createPublicKey (key: U5<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,JsonWebKeyInput,KeyObject,PublicKeyInput>) : KeyObject
static member createSecretKey (key: string, encoding: BufferEncoding) : KeyObject
static member createSecretKey (key: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : KeyObject
static member createSign (algorithm: string, ?options: WritableOptions<Writable>) : Sign
static member createVerify (algorithm: string, ?options: WritableOptions<Writable>) : Verify
static member diffieHellman (options: Options) : NonSharedBuffer
static member generateKey (type: Type, options: Options, callback: Callback) : unit
static member generateKeyPairSync (type: string, options: X448KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: X25519KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: ED448KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, ?options: ED25519KeyPairKeyObjectOptions) : KeyPairKeyObjectResult
static member generateKeyPairSync (type: string, options: ED25519KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: ECKeyPairKeyObjectOptions) : KeyPairKeyObjectResult
static member generateKeyPairSync (type: string, options: ECKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: DSAKeyPairKeyObjectOptions) : KeyPairKeyObjectResult
static member generateKeyPairSync (type: string, options: DSAKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: RSAPSSKeyPairKeyObjectOptions) : KeyPairKeyObjectResult
static member generateKeyPairSync (type: string, options: RSAPSSKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: RSAKeyPairKeyObjectOptions) : KeyPairKeyObjectResult
static member generateKeyPairSync (type: string, options: RSAKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeySync (type: Type, options: Options) : KeyObject
static member generatePrime (size: float, options: GeneratePrimeOptions, callback: Callback4) : unit
static member generatePrime (size: float, options: GeneratePrimeOptionsArrayBuffer, callback: Callback3) : unit
static member generatePrime (size: float, options: GeneratePrimeOptionsBigInt, callback: Callback2) : unit
static member generatePrime (size: float, callback: Callback) : unit
static member generatePrimeSync (size: float, options: GeneratePrimeOptions) : U2<bigint,ArrayBuffer>
static member generatePrimeSync (size: float, options: GeneratePrimeOptionsArrayBuffer) : ArrayBuffer
static member generatePrimeSync (size: float, options: GeneratePrimeOptionsBigInt) : bigint
static member generatePrimeSync (size: float) : ArrayBuffer
static member getCipherInfo (nameOrNid: OpenMode, ?options: CipherInfoOptions) : CipherInfo option
static member getCiphers () : string array
static member getCurves () : string array
static member getDiffieHellman (groupName: string) : DiffieHellmanGroup
static member getFips () : DoesZapCodeSpaceFlag
static member getHashes () : string array
static member getRandomValues<'T> (typedArray: 'T) : 'T
static member hash (algorithm: string, data: BinaryLike, ?outputEncoding: OutputEncoding) : U2<string,NonSharedBuffer>
static member hash (algorithm: string, data: BinaryLike, outputEncoding: string) : NonSharedBuffer
static member hash (algorithm: string, data: BinaryLike, ?outputEncoding: BinaryToTextEncoding) : string
static member hkdf (digest: string, irm: CipherKey, salt: BinaryLike, info: BinaryLike, keylen: float, callback: Callback) : unit
static member hkdfSync (digest: string, ikm: CipherKey, salt: BinaryLike, info: BinaryLike, keylen: float) : ArrayBuffer
static member pbkdf2 (password: BinaryLike, salt: BinaryLike, iterations: float, keylen: float, digest: string, callback: Callback) : unit
static member pbkdf2Sync (password: BinaryLike, salt: BinaryLike, iterations: float, keylen: float, digest: string) : NonSharedBuffer
static member privateDecrypt (privateKey: U4<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey>, buffer: BinaryLike) : NonSharedBuffer
static member privateEncrypt (privateKey: U4<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey>, buffer: BinaryLike) : NonSharedBuffer
static member pseudoRandomBytes (size: float, callback: Callback) : unit
static member pseudoRandomBytes (size: float) : NonSharedBuffer
static member publicDecrypt (key: U5<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey,RsaPublicKey>, buffer: BinaryLike) : NonSharedBuffer
static member publicEncrypt (key: U5<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey,RsaPublicKey>, buffer: BinaryLike) : NonSharedBuffer
static member randomBytes (size: float, callback: Callback) : unit
static member randomBytes (size: float) : NonSharedBuffer
static member randomFill<'T> (buffer: 'T, offset: float, size: float, callback: Callback3<'T>) : unit
static member randomFill<'T> (buffer: 'T, offset: float, callback: Callback2<'T>) : unit
static member randomFill<'T> (buffer: 'T, callback: Callback<'T>) : unit
static member randomFillSync<'T> (buffer: 'T, ?offset: float, ?size: float) : 'T
static member randomInt (min: float, max: float, callback: Callback2) : unit
static member randomInt (max: float, callback: Callback) : unit
static member randomInt (min: float, max: float) : float
static member randomInt (max: float) : float
static member randomUUID (?options: RandomUUIDOptions) : string
static member scrypt (password: BinaryLike, salt: BinaryLike, keylen: float, options: ScryptOptions, callback: Callback2) : unit
static member scrypt (password: BinaryLike, salt: BinaryLike, keylen: float, callback: Callback) : unit
static member scryptSync (password: BinaryLike, salt: BinaryLike, keylen: float, ?options: ScryptOptions) : NonSharedBuffer
static member secureHeapUsed () : SecureHeapUsage
static member setEngine (engine: string, ?flags: float) : unit
static member setFips (bool: bool) : unit
static member sign (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,SignJsonWebKeyInput,SignKeyObjectInput,SignPrivateKeyInput>, callback: Callback) : unit
static member sign (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,SignJsonWebKeyInput,SignKeyObjectInput,SignPrivateKeyInput>) : NonSharedBuffer
static member timingSafeEqual (a: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, b: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : bool
static member verify (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,VerifyJsonWebKeyInput,VerifyKeyObjectInput,VerifyPublicKeyInput>, signature: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, callback: Callback) : unit
static member verify (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,VerifyJsonWebKeyInput,VerifyKeyObjectInput,VerifyPublicKeyInput>, signature: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : bool| Assembly | Xantham.Fable.Node |
| Attributes | [<Erase>] |
The package's value exports, each bound to its import.
Properties
static member DiffieHellmanGroup: DiffieHellmanGroupConstructor
static member DiffieHellmanGroup: DiffieHellmanGroupConstructorThe DiffieHellmanGroup class takes a well-known modp group as its argument. It works the same as DiffieHellman, except that it does not allow changing its keys after creation. In other words, it does not implement setPublicKey() or setPrivateKey() methods.
const { createDiffieHellmanGroup } = await import('node:crypto');
const dh = createDiffieHellmanGroup('modp1');
The name (e.g. 'modp1') is taken from RFC 2412 (modp1 and 2) and RFC 3526:
$ perl -ne 'print "$1\n" if /"(modp\d+)"/' src/node_crypto_groups.h
modp1 # 768 bits
modp2 # 1024 bits
modp5 # 1536 bits
modp14 # 2048 bits
modp15 # etc.
modp16
modp17
modp18
@since v0.7.5
static member fips: bool
static member fips: bool@deprecated since v10.0.0
static member generateKeyPair: GenerateKeyPair
static member generateKeyPair: GenerateKeyPairGenerates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:
const {
generateKeyPair,
} = await import('node:crypto');
generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});
On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.
If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member webcrypto: Crypto
static member webcrypto: CryptoAn implementation of the Web Crypto API standard.
See the Web Crypto API documentation (https://nodejs.org/docs/latest/api/webcrypto.html) for details.
@since v15.0.0
Methods
static member Certificate () : Certificate
static member Certificate () : CertificateSPKAC 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.
@since v0.11.8
static member X509Certificate (buffer: BinaryLike) : X509Certificate
static member X509Certificate (buffer: BinaryLike) : X509CertificateEncapsulates an X509 certificate and provides read-only access to its information.
const { X509Certificate } = await import('node:crypto');
const x509 = new X509Certificate('{... pem encoded cert ...}');
console.log(x509.subject);
@since v15.6.0
static member checkPrime (value: LargeNumberLike, options: CheckPrimeOptions, callback: Callback2) : unit
static member checkPrime (value: LargeNumberLike, options: CheckPrimeOptions, callback: Callback2) : unitChecks the primality of the candidate.
@since v15.8.0
| Parameter | |
|---|---|
candidate | A possible prime encoded as a sequence of big endian octets of arbitrary length. |
static member checkPrime (value: LargeNumberLike, callback: Callback) : unit
static member checkPrime (value: LargeNumberLike, callback: Callback) : unitChecks the primality of the candidate.
@since v15.8.0
| Parameter | |
|---|---|
candidate | A possible prime encoded as a sequence of big endian octets of arbitrary length. |
static member checkPrimeSync (candidate: LargeNumberLike, ?options: CheckPrimeOptions) : bool
static member checkPrimeSync (candidate: LargeNumberLike, ?options: CheckPrimeOptions) : boolChecks the primality of the candidate.
@since v15.8.0
| Parameter | |
|---|---|
candidate | A possible prime encoded as a sequence of big endian octets of arbitrary length. |
Returns. true if the candidate is a prime with an error probability less than 0.25 ** options.checks.
static member createCipheriv (algorithm: string, key: CipherKey, ?iv: BinaryLike, ?options: TransformOptions<Transform>) : Cipher
static member createCipheriv (algorithm: string, key: CipherKey, ?iv: BinaryLike, ?options: TransformOptions<Transform>) : CipherCreates and returns a Cipher object, with the given algorithm, key and initialization vector (iv).
The options argument controls stream behavior and is optional except when a cipher in CCM or OCB mode (e.g. 'aes-128-ccm') is used. In that case, theauthTagLength option is required and specifies the length of the authentication tag in bytes, see CCM mode. In GCM mode, the authTagLengthoption is not required but can be used to set the length of the authentication tag that will be returned by getAuthTag() and defaults to 16 bytes. For chacha20-poly1305, the authTagLength option defaults to 16 bytes.
The algorithm is dependent on OpenSSL, examples are 'aes192', etc. On recent OpenSSL releases, openssl list -cipher-algorithms will display the available cipher algorithms.
The key is the raw key used by the algorithm and iv is an initialization vector. Both arguments must be 'utf8' encoded strings,Buffers, TypedArray, or DataViews. The key may optionally be a KeyObject of type secret. If the cipher does not need an initialization vector, iv may be null.
When passing strings for key or iv, please consider caveats when using strings as inputs to cryptographic APIs.
Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; remember that an attacker must not be able to predict ahead of time what a given IV will be.
@since v0.1.94
| Parameter | |
|---|---|
options | stream.transform options |
static member createCipheriv (algorithm: string, key: CipherKey, iv: BinaryLike, ?options: CipherChaCha20Poly1305Options) : CipherChaCha20Poly1305
static member createCipheriv (algorithm: string, key: CipherKey, iv: BinaryLike, ?options: CipherChaCha20Poly1305Options) : CipherChaCha20Poly1305Creates and returns a Cipher object, with the given algorithm, key and initialization vector (iv).
The options argument controls stream behavior and is optional except when a cipher in CCM or OCB mode (e.g. 'aes-128-ccm') is used. In that case, theauthTagLength option is required and specifies the length of the authentication tag in bytes, see CCM mode. In GCM mode, the authTagLengthoption is not required but can be used to set the length of the authentication tag that will be returned by getAuthTag() and defaults to 16 bytes. For chacha20-poly1305, the authTagLength option defaults to 16 bytes.
The algorithm is dependent on OpenSSL, examples are 'aes192', etc. On recent OpenSSL releases, openssl list -cipher-algorithms will display the available cipher algorithms.
The key is the raw key used by the algorithm and iv is an initialization vector. Both arguments must be 'utf8' encoded strings,Buffers, TypedArray, or DataViews. The key may optionally be a KeyObject of type secret. If the cipher does not need an initialization vector, iv may be null.
When passing strings for key or iv, please consider caveats when using strings as inputs to cryptographic APIs.
Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; remember that an attacker must not be able to predict ahead of time what a given IV will be.
@since v0.1.94
| Parameter | |
|---|---|
options | stream.transform options |
static member createCipheriv (algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike, ?options: CipherGCMOptions) : CipherGCM
static member createCipheriv (algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike, ?options: CipherGCMOptions) : CipherGCMCreates and returns a Cipher object, with the given algorithm, key and initialization vector (iv).
The options argument controls stream behavior and is optional except when a cipher in CCM or OCB mode (e.g. 'aes-128-ccm') is used. In that case, theauthTagLength option is required and specifies the length of the authentication tag in bytes, see CCM mode. In GCM mode, the authTagLengthoption is not required but can be used to set the length of the authentication tag that will be returned by getAuthTag() and defaults to 16 bytes. For chacha20-poly1305, the authTagLength option defaults to 16 bytes.
The algorithm is dependent on OpenSSL, examples are 'aes192', etc. On recent OpenSSL releases, openssl list -cipher-algorithms will display the available cipher algorithms.
The key is the raw key used by the algorithm and iv is an initialization vector. Both arguments must be 'utf8' encoded strings,Buffers, TypedArray, or DataViews. The key may optionally be a KeyObject of type secret. If the cipher does not need an initialization vector, iv may be null.
When passing strings for key or iv, please consider caveats when using strings as inputs to cryptographic APIs.
Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; remember that an attacker must not be able to predict ahead of time what a given IV will be.
@since v0.1.94
| Parameter | |
|---|---|
options | stream.transform options |
static member createCipheriv (algorithm: CipherOCBTypes, key: CipherKey, iv: BinaryLike, options: CipherOCBOptions) : CipherOCB
static member createCipheriv (algorithm: CipherOCBTypes, key: CipherKey, iv: BinaryLike, options: CipherOCBOptions) : CipherOCBCreates and returns a Cipher object, with the given algorithm, key and initialization vector (iv).
The options argument controls stream behavior and is optional except when a cipher in CCM or OCB mode (e.g. 'aes-128-ccm') is used. In that case, theauthTagLength option is required and specifies the length of the authentication tag in bytes, see CCM mode. In GCM mode, the authTagLengthoption is not required but can be used to set the length of the authentication tag that will be returned by getAuthTag() and defaults to 16 bytes. For chacha20-poly1305, the authTagLength option defaults to 16 bytes.
The algorithm is dependent on OpenSSL, examples are 'aes192', etc. On recent OpenSSL releases, openssl list -cipher-algorithms will display the available cipher algorithms.
The key is the raw key used by the algorithm and iv is an initialization vector. Both arguments must be 'utf8' encoded strings,Buffers, TypedArray, or DataViews. The key may optionally be a KeyObject of type secret. If the cipher does not need an initialization vector, iv may be null.
When passing strings for key or iv, please consider caveats when using strings as inputs to cryptographic APIs.
Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; remember that an attacker must not be able to predict ahead of time what a given IV will be.
@since v0.1.94
| Parameter | |
|---|---|
options | stream.transform options |
static member createCipheriv (algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike, options: CipherCCMOptions) : CipherCCM
static member createCipheriv (algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike, options: CipherCCMOptions) : CipherCCMCreates and returns a Cipher object, with the given algorithm, key and initialization vector (iv).
The options argument controls stream behavior and is optional except when a cipher in CCM or OCB mode (e.g. 'aes-128-ccm') is used. In that case, theauthTagLength option is required and specifies the length of the authentication tag in bytes, see CCM mode. In GCM mode, the authTagLengthoption is not required but can be used to set the length of the authentication tag that will be returned by getAuthTag() and defaults to 16 bytes. For chacha20-poly1305, the authTagLength option defaults to 16 bytes.
The algorithm is dependent on OpenSSL, examples are 'aes192', etc. On recent OpenSSL releases, openssl list -cipher-algorithms will display the available cipher algorithms.
The key is the raw key used by the algorithm and iv is an initialization vector. Both arguments must be 'utf8' encoded strings,Buffers, TypedArray, or DataViews. The key may optionally be a KeyObject of type secret. If the cipher does not need an initialization vector, iv may be null.
When passing strings for key or iv, please consider caveats when using strings as inputs to cryptographic APIs.
Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; remember that an attacker must not be able to predict ahead of time what a given IV will be.
@since v0.1.94
| Parameter | |
|---|---|
options | stream.transform options |
static member createDecipheriv (algorithm: string, key: CipherKey, ?iv: BinaryLike, ?options: TransformOptions<Transform>) : Decipher
static member createDecipheriv (algorithm: string, key: CipherKey, ?iv: BinaryLike, ?options: TransformOptions<Transform>) : DecipherCreates and returns a Decipher object that uses the given algorithm, key and initialization vector (iv).
The options argument controls stream behavior and is optional except when a cipher in CCM or OCB mode (e.g. 'aes-128-ccm') is used. In that case, the authTagLength option is required and specifies the length of the authentication tag in bytes, see CCM mode. In GCM mode, the authTagLength option is not required but can be used to restrict accepted authentication tags to those with the specified length. For chacha20-poly1305, the authTagLength option defaults to 16 bytes.
The algorithm is dependent on OpenSSL, examples are 'aes192', etc. On recent OpenSSL releases, openssl list -cipher-algorithms will display the available cipher algorithms.
The key is the raw key used by the algorithm and iv is an initialization vector. Both arguments must be 'utf8' encoded strings,Buffers, TypedArray, or DataViews. The key may optionally be a KeyObject of type secret. If the cipher does not need an initialization vector, iv may be null.
When passing strings for key or iv, please consider caveats when using strings as inputs to cryptographic APIs.
Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; remember that an attacker must not be able to predict ahead of time what a given IV will be.
@since v0.1.94
| Parameter | |
|---|---|
options | stream.transform options |
static member createDecipheriv (algorithm: string, key: CipherKey, iv: BinaryLike, ?options: CipherChaCha20Poly1305Options) : DecipherChaCha20Poly1305
static member createDecipheriv (algorithm: string, key: CipherKey, iv: BinaryLike, ?options: CipherChaCha20Poly1305Options) : DecipherChaCha20Poly1305Creates and returns a Decipher object that uses the given algorithm, key and initialization vector (iv).
The options argument controls stream behavior and is optional except when a cipher in CCM or OCB mode (e.g. 'aes-128-ccm') is used. In that case, the authTagLength option is required and specifies the length of the authentication tag in bytes, see CCM mode. In GCM mode, the authTagLength option is not required but can be used to restrict accepted authentication tags to those with the specified length. For chacha20-poly1305, the authTagLength option defaults to 16 bytes.
The algorithm is dependent on OpenSSL, examples are 'aes192', etc. On recent OpenSSL releases, openssl list -cipher-algorithms will display the available cipher algorithms.
The key is the raw key used by the algorithm and iv is an initialization vector. Both arguments must be 'utf8' encoded strings,Buffers, TypedArray, or DataViews. The key may optionally be a KeyObject of type secret. If the cipher does not need an initialization vector, iv may be null.
When passing strings for key or iv, please consider caveats when using strings as inputs to cryptographic APIs.
Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; remember that an attacker must not be able to predict ahead of time what a given IV will be.
@since v0.1.94
| Parameter | |
|---|---|
options | stream.transform options |
static member createDecipheriv (algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike, ?options: CipherGCMOptions) : DecipherGCM
static member createDecipheriv (algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike, ?options: CipherGCMOptions) : DecipherGCMCreates and returns a Decipher object that uses the given algorithm, key and initialization vector (iv).
The options argument controls stream behavior and is optional except when a cipher in CCM or OCB mode (e.g. 'aes-128-ccm') is used. In that case, the authTagLength option is required and specifies the length of the authentication tag in bytes, see CCM mode. In GCM mode, the authTagLength option is not required but can be used to restrict accepted authentication tags to those with the specified length. For chacha20-poly1305, the authTagLength option defaults to 16 bytes.
The algorithm is dependent on OpenSSL, examples are 'aes192', etc. On recent OpenSSL releases, openssl list -cipher-algorithms will display the available cipher algorithms.
The key is the raw key used by the algorithm and iv is an initialization vector. Both arguments must be 'utf8' encoded strings,Buffers, TypedArray, or DataViews. The key may optionally be a KeyObject of type secret. If the cipher does not need an initialization vector, iv may be null.
When passing strings for key or iv, please consider caveats when using strings as inputs to cryptographic APIs.
Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; remember that an attacker must not be able to predict ahead of time what a given IV will be.
@since v0.1.94
| Parameter | |
|---|---|
options | stream.transform options |
static member createDecipheriv (algorithm: CipherOCBTypes, key: CipherKey, iv: BinaryLike, options: CipherOCBOptions) : DecipherOCB
static member createDecipheriv (algorithm: CipherOCBTypes, key: CipherKey, iv: BinaryLike, options: CipherOCBOptions) : DecipherOCBCreates and returns a Decipher object that uses the given algorithm, key and initialization vector (iv).
The options argument controls stream behavior and is optional except when a cipher in CCM or OCB mode (e.g. 'aes-128-ccm') is used. In that case, the authTagLength option is required and specifies the length of the authentication tag in bytes, see CCM mode. In GCM mode, the authTagLength option is not required but can be used to restrict accepted authentication tags to those with the specified length. For chacha20-poly1305, the authTagLength option defaults to 16 bytes.
The algorithm is dependent on OpenSSL, examples are 'aes192', etc. On recent OpenSSL releases, openssl list -cipher-algorithms will display the available cipher algorithms.
The key is the raw key used by the algorithm and iv is an initialization vector. Both arguments must be 'utf8' encoded strings,Buffers, TypedArray, or DataViews. The key may optionally be a KeyObject of type secret. If the cipher does not need an initialization vector, iv may be null.
When passing strings for key or iv, please consider caveats when using strings as inputs to cryptographic APIs.
Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; remember that an attacker must not be able to predict ahead of time what a given IV will be.
@since v0.1.94
| Parameter | |
|---|---|
options | stream.transform options |
static member createDecipheriv (algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike, options: CipherCCMOptions) : DecipherCCM
static member createDecipheriv (algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike, options: CipherCCMOptions) : DecipherCCMCreates and returns a Decipher object that uses the given algorithm, key and initialization vector (iv).
The options argument controls stream behavior and is optional except when a cipher in CCM or OCB mode (e.g. 'aes-128-ccm') is used. In that case, the authTagLength option is required and specifies the length of the authentication tag in bytes, see CCM mode. In GCM mode, the authTagLength option is not required but can be used to restrict accepted authentication tags to those with the specified length. For chacha20-poly1305, the authTagLength option defaults to 16 bytes.
The algorithm is dependent on OpenSSL, examples are 'aes192', etc. On recent OpenSSL releases, openssl list -cipher-algorithms will display the available cipher algorithms.
The key is the raw key used by the algorithm and iv is an initialization vector. Both arguments must be 'utf8' encoded strings,Buffers, TypedArray, or DataViews. The key may optionally be a KeyObject of type secret. If the cipher does not need an initialization vector, iv may be null.
When passing strings for key or iv, please consider caveats when using strings as inputs to cryptographic APIs.
Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; remember that an attacker must not be able to predict ahead of time what a given IV will be.
@since v0.1.94
| Parameter | |
|---|---|
options | stream.transform options |
static member createDiffieHellman (prime: string, primeEncoding: BinaryToTextEncoding, generator: string, generatorEncoding: BinaryToTextEncoding) : DiffieHellman
static member createDiffieHellman (prime: string, primeEncoding: BinaryToTextEncoding, generator: string, generatorEncoding: BinaryToTextEncoding) : DiffieHellmanCreates a DiffieHellman key exchange object using the supplied prime and an optional specific generator.
The generator argument can be a number, string, or Buffer. If generator is not specified, the value 2 is used.
If primeEncoding is specified, prime is expected to be a string; otherwise a Buffer, TypedArray, or DataView is expected.
If generatorEncoding is specified, generator is expected to be a string; otherwise a number, Buffer, TypedArray, or DataView is expected.
@since v0.11.12
| Parameter | |
|---|---|
primeEncoding | The encoding of the prime string. |
generatorEncoding | The encoding of the generator string. |
static member createDiffieHellman (prime: string, primeEncoding: BinaryToTextEncoding, ?generator: U14<float,ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : DiffieHellman
static member createDiffieHellman (prime: string, primeEncoding: BinaryToTextEncoding, ?generator: U14<float,ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : DiffieHellmanCreates a DiffieHellman key exchange object using the supplied prime and an optional specific generator.
The generator argument can be a number, string, or Buffer. If generator is not specified, the value 2 is used.
If primeEncoding is specified, prime is expected to be a string; otherwise a Buffer, TypedArray, or DataView is expected.
If generatorEncoding is specified, generator is expected to be a string; otherwise a number, Buffer, TypedArray, or DataView is expected.
@since v0.11.12
| Parameter | |
|---|---|
primeEncoding | The encoding of the prime string. |
generatorEncoding | The encoding of the generator string. |
static member createDiffieHellman (prime: U13<ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, generator: string, generatorEncoding: BinaryToTextEncoding) : DiffieHellman
static member createDiffieHellman (prime: U13<ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, generator: string, generatorEncoding: BinaryToTextEncoding) : DiffieHellmanCreates a DiffieHellman key exchange object using the supplied prime and an optional specific generator.
The generator argument can be a number, string, or Buffer. If generator is not specified, the value 2 is used.
If primeEncoding is specified, prime is expected to be a string; otherwise a Buffer, TypedArray, or DataView is expected.
If generatorEncoding is specified, generator is expected to be a string; otherwise a number, Buffer, TypedArray, or DataView is expected.
@since v0.11.12
| Parameter | |
|---|---|
primeEncoding | The encoding of the prime string. |
generatorEncoding | The encoding of the generator string. |
static member createDiffieHellman (prime: U13<ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, ?generator: U14<float,ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : DiffieHellman
static member createDiffieHellman (prime: U13<ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, ?generator: U14<float,ArrayBuffer,BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : DiffieHellmanCreates a DiffieHellman key exchange object using the supplied prime and an optional specific generator.
The generator argument can be a number, string, or Buffer. If generator is not specified, the value 2 is used.
If primeEncoding is specified, prime is expected to be a string; otherwise a Buffer, TypedArray, or DataView is expected.
If generatorEncoding is specified, generator is expected to be a string; otherwise a number, Buffer, TypedArray, or DataView is expected.
@since v0.11.12
| Parameter | |
|---|---|
primeEncoding | The encoding of the prime string. |
generatorEncoding | The encoding of the generator string. |
static member createDiffieHellman (primeLength: float, ?generator: float) : DiffieHellman
static member createDiffieHellman (primeLength: float, ?generator: float) : DiffieHellmanCreates a DiffieHellman key exchange object using the supplied prime and an optional specific generator.
The generator argument can be a number, string, or Buffer. If generator is not specified, the value 2 is used.
If primeEncoding is specified, prime is expected to be a string; otherwise a Buffer, TypedArray, or DataView is expected.
If generatorEncoding is specified, generator is expected to be a string; otherwise a number, Buffer, TypedArray, or DataView is expected.
@since v0.11.12
| Parameter | |
|---|---|
primeEncoding | The encoding of the prime string. |
generatorEncoding | The encoding of the generator string. |
static member createDiffieHellmanGroup (name: string) : DiffieHellmanGroup
static member createDiffieHellmanGroup (name: string) : DiffieHellmanGroupAn alias for getDiffieHellman
@since v0.9.3
static member createECDH (curveName: string) : ECDH
static member createECDH (curveName: string) : ECDHCreates an Elliptic Curve Diffie-Hellman (ECDH) key exchange object using a predefined curve specified by the curveName string. Use getCurves to obtain a list of available curve names. On recent OpenSSL releases, openssl ecparam -list_curves will also display the name and description of each available elliptic curve.
@since v0.11.14
static member createHash (algorithm: string, ?options: HashOptions) : Hash
static member createHash (algorithm: string, ?options: HashOptions) : HashCreates and returns a Hash object that can be used to generate hash digests using the given algorithm. Optional options argument controls stream behavior. For XOF hash functions such as 'shake256', the outputLength option can be used to specify the desired output length in bytes.
The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list -digest-algorithms will display the available digest algorithms.
Example: generating the sha256 sum of a file
import {
createReadStream,
} from 'node:fs';
import { argv } from 'node:process';
const {
createHash,
} = await import('node:crypto');
const filename = argv[2];
const hash = createHash('sha256');
const input = createReadStream(filename);
input.on('readable', () => {
// Only one element is going to be produced by the
// hash stream.
const data = input.read();
if (data)
hash.update(data);
else {
console.log(`${hash.digest('hex')} ${filename}`);
}
});
@since v0.1.92
| Parameter | |
|---|---|
options | stream.transform options |
static member createHmac (algorithm: string, key: CipherKey, ?options: TransformOptions<Transform>) : Hmac
static member createHmac (algorithm: string, key: CipherKey, ?options: TransformOptions<Transform>) : HmacCreates and returns an Hmac object that uses the given algorithm and key. Optional options argument controls stream behavior.
The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list -digest-algorithms will display the available digest algorithms.
The key is the HMAC key used to generate the cryptographic HMAC hash. If it is a KeyObject, its type must be secret. If it is a string, please consider caveats when using strings as inputs to cryptographic APIs. If it was obtained from a cryptographically secure source of entropy, such as randomBytes or generateKey, its length should not exceed the block size of algorithm (e.g., 512 bits for SHA-256).
Example: generating the sha256 HMAC of a file
import {
createReadStream,
} from 'node:fs';
import { argv } from 'node:process';
const {
createHmac,
} = await import('node:crypto');
const filename = argv[2];
const hmac = createHmac('sha256', 'a secret');
const input = createReadStream(filename);
input.on('readable', () => {
// Only one element is going to be produced by the
// hash stream.
const data = input.read();
if (data)
hmac.update(data);
else {
console.log(`${hmac.digest('hex')} ${filename}`);
}
});
@since v0.1.94
| Parameter | |
|---|---|
options | stream.transform options |
static member createPrivateKey (key: U4<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,JsonWebKeyInput,PrivateKeyInput>) : KeyObject
static member createPrivateKey (key: U4<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,JsonWebKeyInput,PrivateKeyInput>) : KeyObjectCreates and returns a new key object containing a private key. If key is a string or Buffer, format is assumed to be 'pem'; otherwise, key must be an object with the properties described above.
If the private key is encrypted, a passphrase must be specified. The length of the passphrase is limited to 1024 bytes.
@since v11.6.0
static member createPublicKey (key: U5<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,JsonWebKeyInput,KeyObject,PublicKeyInput>) : KeyObject
static member createPublicKey (key: U5<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,JsonWebKeyInput,KeyObject,PublicKeyInput>) : KeyObjectCreates and returns a new key object containing a public key. If key is a string or Buffer, format is assumed to be 'pem'; if key is a KeyObject with type 'private', the public key is derived from the given private key; otherwise, key must be an object with the properties described above.
If the format is 'pem', the 'key' may also be an X.509 certificate.
Because public keys can be derived from private keys, a private key may be passed instead of a public key. In that case, this function behaves as if createPrivateKey had been called, except that the type of the returned KeyObject will be 'public' and that the private key cannot be extracted from the returned KeyObject. Similarly, if a KeyObject with type 'private' is given, a new KeyObject with type 'public' will be returned and it will be impossible to extract the private key from the returned object.
@since v11.6.0
static member createSecretKey (key: string, encoding: BufferEncoding) : KeyObject
static member createSecretKey (key: string, encoding: BufferEncoding) : KeyObjectCreates and returns a new key object containing a secret key for symmetric encryption or Hmac.
@since v11.6.0
| Parameter | |
|---|---|
encoding | The string encoding when key is a string. |
static member createSecretKey (key: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : KeyObject
static member createSecretKey (key: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : KeyObjectCreates and returns a new key object containing a secret key for symmetric encryption or Hmac.
@since v11.6.0
| Parameter | |
|---|---|
encoding | The string encoding when key is a string. |
static member createSign (algorithm: string, ?options: WritableOptions<Writable>) : Sign
static member createSign (algorithm: string, ?options: WritableOptions<Writable>) : SignCreates and returns a Sign object that uses the given algorithm. Use getHashes to obtain the names of the available digest algorithms. Optional options argument controls the stream.Writable behavior.
In some cases, a Sign instance can be created using the name of a signature algorithm, such as 'RSA-SHA256', instead of a digest algorithm. This will use the corresponding digest algorithm. This does not work for all signature algorithms, such as 'ecdsa-with-SHA256', so it is best to always use digest algorithm names.
@since v0.1.92
| Parameter | |
|---|---|
options | stream.Writable options |
static member createVerify (algorithm: string, ?options: WritableOptions<Writable>) : Verify
static member createVerify (algorithm: string, ?options: WritableOptions<Writable>) : VerifyCreates and returns a Verify object that uses the given algorithm. Use getHashes to obtain an array of names of the available signing algorithms. Optional options argument controls the stream.Writable behavior.
In some cases, a Verify instance can be created using the name of a signature algorithm, such as 'RSA-SHA256', instead of a digest algorithm. This will use the corresponding digest algorithm. This does not work for all signature algorithms, such as 'ecdsa-with-SHA256', so it is best to always use digest algorithm names.
@since v0.1.92
| Parameter | |
|---|---|
options | stream.Writable options |
static member diffieHellman (options: Options) : NonSharedBuffer
static member diffieHellman (options: Options) : NonSharedBufferComputes the Diffie-Hellman secret based on a privateKey and a publicKey. Both keys must have the same asymmetricKeyType, which must be one of 'dh' (for Diffie-Hellman), 'ec' (for ECDH), 'x448', or 'x25519' (for ECDH-ES).
@since v13.9.0, v12.17.0
static member generateKey (type: Type, options: Options, callback: Callback) : unit
static member generateKey (type: Type, options: Options, callback: Callback) : unitAsynchronously generates a new random secret key of the given length. The type will determine which validations will be performed on the length.
const {
generateKey,
} = await import('node:crypto');
generateKey('hmac', { length: 512 }, (err, key) => {
if (err) throw err;
console.log(key.export().toString('hex')); // 46e..........620
});
The size of a generated HMAC key should not exceed the block size of the underlying hash function. See createHmac for more information.
@since v15.0.0
| Parameter | |
|---|---|
type | The intended use of the generated secret key. Currently accepted values are 'hmac' and 'aes'. |
static member generateKeyPairSync (type: string, options: X448KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: X448KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>Generates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, options: X25519KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: X25519KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>Generates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, options: ED448KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: ED448KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>Generates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, ?options: ED25519KeyPairKeyObjectOptions) : KeyPairKeyObjectResult
static member generateKeyPairSync (type: string, ?options: ED25519KeyPairKeyObjectOptions) : KeyPairKeyObjectResultGenerates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, options: ED25519KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: ED25519KeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>Generates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, options: ECKeyPairKeyObjectOptions) : KeyPairKeyObjectResult
static member generateKeyPairSync (type: string, options: ECKeyPairKeyObjectOptions) : KeyPairKeyObjectResultGenerates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, options: ECKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: ECKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>Generates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, options: DSAKeyPairKeyObjectOptions) : KeyPairKeyObjectResult
static member generateKeyPairSync (type: string, options: DSAKeyPairKeyObjectOptions) : KeyPairKeyObjectResultGenerates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, options: DSAKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: DSAKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>Generates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, options: RSAPSSKeyPairKeyObjectOptions) : KeyPairKeyObjectResult
static member generateKeyPairSync (type: string, options: RSAPSSKeyPairKeyObjectOptions) : KeyPairKeyObjectResultGenerates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, options: RSAPSSKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: RSAPSSKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>Generates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, options: RSAKeyPairKeyObjectOptions) : KeyPairKeyObjectResult
static member generateKeyPairSync (type: string, options: RSAKeyPairKeyObjectOptions) : KeyPairKeyObjectResultGenerates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeyPairSync (type: string, options: RSAKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>
static member generateKeyPairSync (type: string, options: RSAKeyPairOptions<string,string>) : U4<KeyPairSyncResult<string,string>,KeyPairSyncResult<string,NonSharedBuffer>,KeyPairSyncResult<NonSharedBuffer,string>,KeyPairSyncResult<NonSharedBuffer,NonSharedBuffer>>Generates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC, Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding private keys, it is recommended to use 'pkcs8' with a strong passphrase, and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair. When PEM encoding was selected, the respective key will be a string, otherwise it will be a buffer containing the data encoded as DER.
@since v10.12.0
| Parameter | |
|---|---|
type | Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'. |
static member generateKeySync (type: Type, options: Options) : KeyObject
static member generateKeySync (type: Type, options: Options) : KeyObjectSynchronously generates a new random secret key of the given length. The type will determine which validations will be performed on the length.
const {
generateKeySync,
} = await import('node:crypto');
const key = generateKeySync('hmac', { length: 512 });
console.log(key.export().toString('hex')); // e89..........41e
The size of a generated HMAC key should not exceed the block size of the underlying hash function. See createHmac for more information.
@since v15.0.0
| Parameter | |
|---|---|
type | The intended use of the generated secret key. Currently accepted values are 'hmac' and 'aes'. |
static member generatePrime (size: float, options: GeneratePrimeOptions, callback: Callback4) : unit
static member generatePrime (size: float, options: GeneratePrimeOptions, callback: Callback4) : unitGenerates a pseudorandom prime of size bits.
If options.safe is true, the prime will be a safe prime -- that is, (prime - 1) / 2 will also be a prime.
The options.add and options.rem parameters can be used to enforce additional requirements, e.g., for Diffie-Hellman:
- If
options.addandoptions.remare both set, the prime will satisfy the condition thatprime % add = rem. - If only
options.addis set andoptions.safeis nottrue, the prime will satisfy the condition thatprime % add = 1. - If only
options.addis set andoptions.safeis set totrue, the prime will instead satisfy the condition thatprime % add = 3. This is necessary becauseprime % add = 1foroptions.add > 2would contradict the condition enforced byoptions.safe. options.remis ignored ifoptions.addis not given.
Both options.add and options.rem must be encoded as big-endian sequences if given as an ArrayBuffer, SharedArrayBuffer, TypedArray, Buffer, or DataView.
By default, the prime is encoded as a big-endian sequence of octets in an ArrayBuffer. If the bigint option is true, then a bigint is provided.
@since v15.8.0
| Parameter | |
|---|---|
size | The size (in bits) of the prime to generate. |
static member generatePrime (size: float, options: GeneratePrimeOptionsArrayBuffer, callback: Callback3) : unit
static member generatePrime (size: float, options: GeneratePrimeOptionsArrayBuffer, callback: Callback3) : unitGenerates a pseudorandom prime of size bits.
If options.safe is true, the prime will be a safe prime -- that is, (prime - 1) / 2 will also be a prime.
The options.add and options.rem parameters can be used to enforce additional requirements, e.g., for Diffie-Hellman:
- If
options.addandoptions.remare both set, the prime will satisfy the condition thatprime % add = rem. - If only
options.addis set andoptions.safeis nottrue, the prime will satisfy the condition thatprime % add = 1. - If only
options.addis set andoptions.safeis set totrue, the prime will instead satisfy the condition thatprime % add = 3. This is necessary becauseprime % add = 1foroptions.add > 2would contradict the condition enforced byoptions.safe. options.remis ignored ifoptions.addis not given.
Both options.add and options.rem must be encoded as big-endian sequences if given as an ArrayBuffer, SharedArrayBuffer, TypedArray, Buffer, or DataView.
By default, the prime is encoded as a big-endian sequence of octets in an ArrayBuffer. If the bigint option is true, then a bigint is provided.
@since v15.8.0
| Parameter | |
|---|---|
size | The size (in bits) of the prime to generate. |
static member generatePrime (size: float, options: GeneratePrimeOptionsBigInt, callback: Callback2) : unit
static member generatePrime (size: float, options: GeneratePrimeOptionsBigInt, callback: Callback2) : unitGenerates a pseudorandom prime of size bits.
If options.safe is true, the prime will be a safe prime -- that is, (prime - 1) / 2 will also be a prime.
The options.add and options.rem parameters can be used to enforce additional requirements, e.g., for Diffie-Hellman:
- If
options.addandoptions.remare both set, the prime will satisfy the condition thatprime % add = rem. - If only
options.addis set andoptions.safeis nottrue, the prime will satisfy the condition thatprime % add = 1. - If only
options.addis set andoptions.safeis set totrue, the prime will instead satisfy the condition thatprime % add = 3. This is necessary becauseprime % add = 1foroptions.add > 2would contradict the condition enforced byoptions.safe. options.remis ignored ifoptions.addis not given.
Both options.add and options.rem must be encoded as big-endian sequences if given as an ArrayBuffer, SharedArrayBuffer, TypedArray, Buffer, or DataView.
By default, the prime is encoded as a big-endian sequence of octets in an ArrayBuffer. If the bigint option is true, then a bigint is provided.
@since v15.8.0
| Parameter | |
|---|---|
size | The size (in bits) of the prime to generate. |
static member generatePrime (size: float, callback: Callback) : unit
static member generatePrime (size: float, callback: Callback) : unitGenerates a pseudorandom prime of size bits.
If options.safe is true, the prime will be a safe prime -- that is, (prime - 1) / 2 will also be a prime.
The options.add and options.rem parameters can be used to enforce additional requirements, e.g., for Diffie-Hellman:
- If
options.addandoptions.remare both set, the prime will satisfy the condition thatprime % add = rem. - If only
options.addis set andoptions.safeis nottrue, the prime will satisfy the condition thatprime % add = 1. - If only
options.addis set andoptions.safeis set totrue, the prime will instead satisfy the condition thatprime % add = 3. This is necessary becauseprime % add = 1foroptions.add > 2would contradict the condition enforced byoptions.safe. options.remis ignored ifoptions.addis not given.
Both options.add and options.rem must be encoded as big-endian sequences if given as an ArrayBuffer, SharedArrayBuffer, TypedArray, Buffer, or DataView.
By default, the prime is encoded as a big-endian sequence of octets in an ArrayBuffer. If the bigint option is true, then a bigint is provided.
@since v15.8.0
| Parameter | |
|---|---|
size | The size (in bits) of the prime to generate. |
static member generatePrimeSync (size: float, options: GeneratePrimeOptions) : U2<bigint,ArrayBuffer>
static member generatePrimeSync (size: float, options: GeneratePrimeOptions) : U2<bigint,ArrayBuffer>Generates a pseudorandom prime of size bits.
If options.safe is true, the prime will be a safe prime -- that is, (prime - 1) / 2 will also be a prime.
The options.add and options.rem parameters can be used to enforce additional requirements, e.g., for Diffie-Hellman:
- If
options.addandoptions.remare both set, the prime will satisfy the condition thatprime % add = rem. - If only
options.addis set andoptions.safeis nottrue, the prime will satisfy the condition thatprime % add = 1. - If only
options.addis set andoptions.safeis set totrue, the prime will instead satisfy the condition thatprime % add = 3. This is necessary becauseprime % add = 1foroptions.add > 2would contradict the condition enforced byoptions.safe. options.remis ignored ifoptions.addis not given.
Both options.add and options.rem must be encoded as big-endian sequences if given as an ArrayBuffer, SharedArrayBuffer, TypedArray, Buffer, or DataView.
By default, the prime is encoded as a big-endian sequence of octets in an ArrayBuffer. If the bigint option is true, then a bigint is provided.
@since v15.8.0
| Parameter | |
|---|---|
size | The size (in bits) of the prime to generate. |
static member generatePrimeSync (size: float, options: GeneratePrimeOptionsArrayBuffer) : ArrayBuffer
static member generatePrimeSync (size: float, options: GeneratePrimeOptionsArrayBuffer) : ArrayBufferGenerates a pseudorandom prime of size bits.
If options.safe is true, the prime will be a safe prime -- that is, (prime - 1) / 2 will also be a prime.
The options.add and options.rem parameters can be used to enforce additional requirements, e.g., for Diffie-Hellman:
- If
options.addandoptions.remare both set, the prime will satisfy the condition thatprime % add = rem. - If only
options.addis set andoptions.safeis nottrue, the prime will satisfy the condition thatprime % add = 1. - If only
options.addis set andoptions.safeis set totrue, the prime will instead satisfy the condition thatprime % add = 3. This is necessary becauseprime % add = 1foroptions.add > 2would contradict the condition enforced byoptions.safe. options.remis ignored ifoptions.addis not given.
Both options.add and options.rem must be encoded as big-endian sequences if given as an ArrayBuffer, SharedArrayBuffer, TypedArray, Buffer, or DataView.
By default, the prime is encoded as a big-endian sequence of octets in an ArrayBuffer. If the bigint option is true, then a bigint is provided.
@since v15.8.0
| Parameter | |
|---|---|
size | The size (in bits) of the prime to generate. |
static member generatePrimeSync (size: float, options: GeneratePrimeOptionsBigInt) : bigint
static member generatePrimeSync (size: float, options: GeneratePrimeOptionsBigInt) : bigintGenerates a pseudorandom prime of size bits.
If options.safe is true, the prime will be a safe prime -- that is, (prime - 1) / 2 will also be a prime.
The options.add and options.rem parameters can be used to enforce additional requirements, e.g., for Diffie-Hellman:
- If
options.addandoptions.remare both set, the prime will satisfy the condition thatprime % add = rem. - If only
options.addis set andoptions.safeis nottrue, the prime will satisfy the condition thatprime % add = 1. - If only
options.addis set andoptions.safeis set totrue, the prime will instead satisfy the condition thatprime % add = 3. This is necessary becauseprime % add = 1foroptions.add > 2would contradict the condition enforced byoptions.safe. options.remis ignored ifoptions.addis not given.
Both options.add and options.rem must be encoded as big-endian sequences if given as an ArrayBuffer, SharedArrayBuffer, TypedArray, Buffer, or DataView.
By default, the prime is encoded as a big-endian sequence of octets in an ArrayBuffer. If the bigint option is true, then a bigint is provided.
@since v15.8.0
| Parameter | |
|---|---|
size | The size (in bits) of the prime to generate. |
static member generatePrimeSync (size: float) : ArrayBuffer
static member generatePrimeSync (size: float) : ArrayBufferGenerates a pseudorandom prime of size bits.
If options.safe is true, the prime will be a safe prime -- that is, (prime - 1) / 2 will also be a prime.
The options.add and options.rem parameters can be used to enforce additional requirements, e.g., for Diffie-Hellman:
- If
options.addandoptions.remare both set, the prime will satisfy the condition thatprime % add = rem. - If only
options.addis set andoptions.safeis nottrue, the prime will satisfy the condition thatprime % add = 1. - If only
options.addis set andoptions.safeis set totrue, the prime will instead satisfy the condition thatprime % add = 3. This is necessary becauseprime % add = 1foroptions.add > 2would contradict the condition enforced byoptions.safe. options.remis ignored ifoptions.addis not given.
Both options.add and options.rem must be encoded as big-endian sequences if given as an ArrayBuffer, SharedArrayBuffer, TypedArray, Buffer, or DataView.
By default, the prime is encoded as a big-endian sequence of octets in an ArrayBuffer. If the bigint option is true, then a bigint is provided.
@since v15.8.0
| Parameter | |
|---|---|
size | The size (in bits) of the prime to generate. |
static member getCipherInfo (nameOrNid: OpenMode, ?options: CipherInfoOptions) : CipherInfo option
static member getCipherInfo (nameOrNid: OpenMode, ?options: CipherInfoOptions) : CipherInfo optionReturns information about a given cipher.
Some ciphers accept variable length keys and initialization vectors. By default, the crypto.getCipherInfo() method will return the default values for these ciphers. To test if a given key length or iv length is acceptable for given cipher, use the keyLength and ivLength options. If the given values are unacceptable, undefined will be returned.
@since v15.0.0
| Parameter | |
|---|---|
nameOrNid | The name or nid of the cipher to query. |
static member getCiphers () : string array
static member getCiphers () : string arrayconst {
getCiphers,
} = await import('node:crypto');
console.log(getCiphers()); // ['aes-128-cbc', 'aes-128-ccm', ...]
@since v0.9.3
Returns. An array with the names of the supported cipher algorithms.
static member getCurves () : string array
static member getCurves () : string arrayconst {
getCurves,
} = await import('node:crypto');
console.log(getCurves()); // ['Oakley-EC2N-3', 'Oakley-EC2N-4', ...]
@since v2.3.0
Returns. An array with the names of the supported elliptic curves.
static member getDiffieHellman (groupName: string) : DiffieHellmanGroup
static member getDiffieHellman (groupName: string) : DiffieHellmanGroupCreates a predefined DiffieHellmanGroup key exchange object. The supported groups are listed in the documentation for DiffieHellmanGroup.
The returned object mimics the interface of objects created by createDiffieHellman, but will not allow changing the keys (with diffieHellman.setPublicKey(), for example). The advantage of using this method is that the parties do not have to generate nor exchange a group modulus beforehand, saving both processor and communication time.
Example (obtaining a shared secret):
const {
getDiffieHellman,
} = await import('node:crypto');
const alice = getDiffieHellman('modp14');
const bob = getDiffieHellman('modp14');
alice.generateKeys();
bob.generateKeys();
const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
const bobSecret = bob.computeSecret(alice.getPublicKey(), null, 'hex');
// aliceSecret and bobSecret should be the same
console.log(aliceSecret === bobSecret);
@since v0.7.5
static member getFips () : DoesZapCodeSpaceFlag
static member getFips () : DoesZapCodeSpaceFlag@since v10.0.0
Returns. 1 if and only if a FIPS compliant crypto provider is currently in use, 0 otherwise. A future semver-major release may change the return type of this API to a .
static member getHashes () : string array
static member getHashes () : string arrayconst {
getHashes,
} = await import('node:crypto');
console.log(getHashes()); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...]
@since v0.9.3
Returns. An array of the names of the supported hash algorithms, such as 'RSA-SHA256'. Hash algorithms are also called "digest" algorithms.
static member getRandomValues<'T> (typedArray: 'T) : 'T
static member getRandomValues<'T> (typedArray: 'T) : 'TA convenient alias for webcrypto.getRandomValues. This implementation is not compliant with the Web Crypto spec, to write web-compatible code use webcrypto.getRandomValues instead.
@since v17.4.0
Returns. Returns typedArray.
static member hash (algorithm: string, data: BinaryLike, ?outputEncoding: OutputEncoding) : U2<string,NonSharedBuffer>
static member hash (algorithm: string, data: BinaryLike, ?outputEncoding: OutputEncoding) : U2<string,NonSharedBuffer>A utility for creating one-shot hash digests of data. It can be faster than the object-based crypto.createHash() when hashing a smaller amount of data (<= 5MB) that's readily available. If the data can be big or if it is streamed, it's still recommended to use crypto.createHash() instead. The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list -digest-algorithms will display the available digest algorithms.
Example:
import crypto from 'node:crypto';
import { Buffer } from 'node:buffer';
// Hashing a string and return the result as a hex-encoded string.
const string = 'Node.js';
// 10b3493287f831e81a438811a1ffba01f8cec4b7
console.log(crypto.hash('sha1', string));
// Encode a base64-encoded string into a Buffer, hash it and return
// the result as a buffer.
const base64 = 'Tm9kZS5qcw==';
// <Buffer 10 b3 49 32 87 f8 31 e8 1a 43 88 11 a1 ff ba 01 f8 ce c4 b7>
console.log(crypto.hash('sha1', Buffer.from(base64, 'base64'), 'buffer'));
@since v21.7.0, v20.12.0
| Parameter | |
|---|---|
data | When data is a string, it will be encoded as UTF-8 before being hashed. If a different input encoding is desired for a string input, user could encode the string into a TypedArray using either TextEncoder or Buffer.from() and passing the encoded TypedArray into this API instead. |
outputEncoding | Encoding used to encode the returned digest. |
static member hash (algorithm: string, data: BinaryLike, outputEncoding: string) : NonSharedBuffer
static member hash (algorithm: string, data: BinaryLike, outputEncoding: string) : NonSharedBufferA utility for creating one-shot hash digests of data. It can be faster than the object-based crypto.createHash() when hashing a smaller amount of data (<= 5MB) that's readily available. If the data can be big or if it is streamed, it's still recommended to use crypto.createHash() instead. The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list -digest-algorithms will display the available digest algorithms.
Example:
import crypto from 'node:crypto';
import { Buffer } from 'node:buffer';
// Hashing a string and return the result as a hex-encoded string.
const string = 'Node.js';
// 10b3493287f831e81a438811a1ffba01f8cec4b7
console.log(crypto.hash('sha1', string));
// Encode a base64-encoded string into a Buffer, hash it and return
// the result as a buffer.
const base64 = 'Tm9kZS5qcw==';
// <Buffer 10 b3 49 32 87 f8 31 e8 1a 43 88 11 a1 ff ba 01 f8 ce c4 b7>
console.log(crypto.hash('sha1', Buffer.from(base64, 'base64'), 'buffer'));
@since v21.7.0, v20.12.0
| Parameter | |
|---|---|
data | When data is a string, it will be encoded as UTF-8 before being hashed. If a different input encoding is desired for a string input, user could encode the string into a TypedArray using either TextEncoder or Buffer.from() and passing the encoded TypedArray into this API instead. |
outputEncoding | Encoding used to encode the returned digest. |
static member hash (algorithm: string, data: BinaryLike, ?outputEncoding: BinaryToTextEncoding) : string
static member hash (algorithm: string, data: BinaryLike, ?outputEncoding: BinaryToTextEncoding) : stringA utility for creating one-shot hash digests of data. It can be faster than the object-based crypto.createHash() when hashing a smaller amount of data (<= 5MB) that's readily available. If the data can be big or if it is streamed, it's still recommended to use crypto.createHash() instead. The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are 'sha256', 'sha512', etc. On recent releases of OpenSSL, openssl list -digest-algorithms will display the available digest algorithms.
Example:
import crypto from 'node:crypto';
import { Buffer } from 'node:buffer';
// Hashing a string and return the result as a hex-encoded string.
const string = 'Node.js';
// 10b3493287f831e81a438811a1ffba01f8cec4b7
console.log(crypto.hash('sha1', string));
// Encode a base64-encoded string into a Buffer, hash it and return
// the result as a buffer.
const base64 = 'Tm9kZS5qcw==';
// <Buffer 10 b3 49 32 87 f8 31 e8 1a 43 88 11 a1 ff ba 01 f8 ce c4 b7>
console.log(crypto.hash('sha1', Buffer.from(base64, 'base64'), 'buffer'));
@since v21.7.0, v20.12.0
| Parameter | |
|---|---|
data | When data is a string, it will be encoded as UTF-8 before being hashed. If a different input encoding is desired for a string input, user could encode the string into a TypedArray using either TextEncoder or Buffer.from() and passing the encoded TypedArray into this API instead. |
outputEncoding | Encoding used to encode the returned digest. |
static member hkdf (digest: string, irm: CipherKey, salt: BinaryLike, info: BinaryLike, keylen: float, callback: Callback) : unit
static member hkdf (digest: string, irm: CipherKey, salt: BinaryLike, info: BinaryLike, keylen: float, callback: Callback) : unitHKDF is a simple key derivation function defined in RFC 5869. The given ikm, salt and info are used with the digest to derive a key of keylen bytes.
The supplied callback function is called with two arguments: err and derivedKey. If an errors occurs while deriving the key, err will be set; otherwise err will be null. The successfully generated derivedKey will be passed to the callback as an ArrayBuffer. An error will be thrown if any of the input arguments specify invalid values or types.
import { Buffer } from 'node:buffer';
const {
hkdf,
} = await import('node:crypto');
hkdf('sha512', 'key', 'salt', 'info', 64, (err, derivedKey) => {
if (err) throw err;
console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
});
@since v15.0.0
| Parameter | |
|---|---|
digest | The digest algorithm to use. |
ikm | The input keying material. Must be provided but can be zero-length. |
salt | The salt value. Must be provided but can be zero-length. |
info | Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes. |
keylen | The length of the key to generate. Must be greater than 0. The maximum allowable value is 255 times the number of bytes produced by the selected digest function (e.g. sha512 generates 64-byte hashes, making the maximum HKDF output 16320 bytes). |
static member hkdfSync (digest: string, ikm: CipherKey, salt: BinaryLike, info: BinaryLike, keylen: float) : ArrayBuffer
static member hkdfSync (digest: string, ikm: CipherKey, salt: BinaryLike, info: BinaryLike, keylen: float) : ArrayBufferProvides a synchronous HKDF key derivation function as defined in RFC 5869. The given ikm, salt and info are used with the digest to derive a key of keylen bytes.
The successfully generated derivedKey will be returned as an ArrayBuffer.
An error will be thrown if any of the input arguments specify invalid values or types, or if the derived key cannot be generated.
import { Buffer } from 'node:buffer';
const {
hkdfSync,
} = await import('node:crypto');
const derivedKey = hkdfSync('sha512', 'key', 'salt', 'info', 64);
console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
@since v15.0.0
| Parameter | |
|---|---|
digest | The digest algorithm to use. |
ikm | The input keying material. Must be provided but can be zero-length. |
salt | The salt value. Must be provided but can be zero-length. |
info | Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes. |
keylen | The length of the key to generate. Must be greater than 0. The maximum allowable value is 255 times the number of bytes produced by the selected digest function (e.g. sha512 generates 64-byte hashes, making the maximum HKDF output 16320 bytes). |
static member pbkdf2 (password: BinaryLike, salt: BinaryLike, iterations: float, keylen: float, digest: string, callback: Callback) : unit
static member pbkdf2 (password: BinaryLike, salt: BinaryLike, iterations: float, keylen: float, digest: string, callback: Callback) : unitProvides an asynchronous Password-Based Key Derivation Function 2 (PBKDF2) implementation. A selected HMAC digest algorithm specified by digest is applied to derive a key of the requested byte length (keylen) from the password, salt and iterations.
The supplied callback function is called with two arguments: err and derivedKey. If an error occurs while deriving the key, err will be set; otherwise err will be null. By default, the successfully generated derivedKey will be passed to the callback as a Buffer. An error will be thrown if any of the input arguments specify invalid values or types.
The iterations argument must be a number set as high as possible. The higher the number of iterations, the more secure the derived key will be, but will take a longer amount of time to complete.
The salt should be as unique as possible. It is recommended that a salt is random and at least 16 bytes long. See NIST SP 800-132 for details.
When passing strings for password or salt, please consider caveats when using strings as inputs to cryptographic APIs.
const {
pbkdf2,
} = await import('node:crypto');
pbkdf2('secret', 'salt', 100000, 64, 'sha512', (err, derivedKey) => {
if (err) throw err;
console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
});
An array of supported digest functions can be retrieved using getHashes.
This API uses libuv's threadpool, which can have surprising and negative performance implications for some applications; see the UV_THREADPOOL_SIZE documentation for more information.
@since v0.5.5
static member pbkdf2Sync (password: BinaryLike, salt: BinaryLike, iterations: float, keylen: float, digest: string) : NonSharedBuffer
static member pbkdf2Sync (password: BinaryLike, salt: BinaryLike, iterations: float, keylen: float, digest: string) : NonSharedBufferProvides a synchronous Password-Based Key Derivation Function 2 (PBKDF2) implementation. A selected HMAC digest algorithm specified by digest is applied to derive a key of the requested byte length (keylen) from the password, salt and iterations.
If an error occurs an Error will be thrown, otherwise the derived key will be returned as a Buffer.
The iterations argument must be a number set as high as possible. The higher the number of iterations, the more secure the derived key will be, but will take a longer amount of time to complete.
The salt should be as unique as possible. It is recommended that a salt is random and at least 16 bytes long. See NIST SP 800-132 for details.
When passing strings for password or salt, please consider caveats when using strings as inputs to cryptographic APIs.
const {
pbkdf2Sync,
} = await import('node:crypto');
const key = pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512');
console.log(key.toString('hex')); // '3745e48...08d59ae'
An array of supported digest functions can be retrieved using getHashes.
@since v0.9.3
static member privateDecrypt (privateKey: U4<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey>, buffer: BinaryLike) : NonSharedBuffer
static member privateDecrypt (privateKey: U4<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey>, buffer: BinaryLike) : NonSharedBufferDecrypts buffer with privateKey. buffer was previously encrypted using the corresponding public key, for example using publicEncrypt.
If privateKey is not a KeyObject, this function behaves as if privateKey had been passed to createPrivateKey. If it is an object, the padding property can be passed. Otherwise, this function uses RSA_PKCS1_OAEP_PADDING.
@since v0.11.14
static member privateEncrypt (privateKey: U4<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey>, buffer: BinaryLike) : NonSharedBuffer
static member privateEncrypt (privateKey: U4<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey>, buffer: BinaryLike) : NonSharedBufferEncrypts buffer with privateKey. The returned data can be decrypted using the corresponding public key, for example using publicDecrypt.
If privateKey is not a KeyObject, this function behaves as if privateKey had been passed to createPrivateKey. If it is an object, the padding property can be passed. Otherwise, this function uses RSA_PKCS1_PADDING.
@since v1.1.0
static member pseudoRandomBytes (size: float) : NonSharedBufferstatic member publicDecrypt (key: U5<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey,RsaPublicKey>, buffer: BinaryLike) : NonSharedBuffer
static member publicDecrypt (key: U5<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey,RsaPublicKey>, buffer: BinaryLike) : NonSharedBufferDecrypts buffer with key.buffer was previously encrypted using the corresponding private key, for example using privateEncrypt.
If key is not a KeyObject, this function behaves as if key had been passed to createPublicKey. If it is an object, the padding property can be passed. Otherwise, this function uses RSA_PKCS1_PADDING.
Because RSA public keys can be derived from private keys, a private key may be passed instead of a public key.
@since v1.1.0
static member publicEncrypt (key: U5<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey,RsaPublicKey>, buffer: BinaryLike) : NonSharedBuffer
static member publicEncrypt (key: U5<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,RsaPrivateKey,RsaPublicKey>, buffer: BinaryLike) : NonSharedBufferEncrypts the content of buffer with key and returns a new Buffer with encrypted content. The returned data can be decrypted using the corresponding private key, for example using privateDecrypt.
If key is not a KeyObject, this function behaves as if key had been passed to createPublicKey. If it is an object, the padding property can be passed. Otherwise, this function uses RSA_PKCS1_OAEP_PADDING.
Because RSA public keys can be derived from private keys, a private key may be passed instead of a public key.
@since v0.11.14
static member randomBytes (size: float, callback: Callback) : unit
static member randomBytes (size: float, callback: Callback) : unitGenerates cryptographically strong pseudorandom data. The size argument is a number indicating the number of bytes to generate.
If a callback function is provided, the bytes are generated asynchronously and the callback function is invoked with two arguments: err and buf. If an error occurs, err will be an Error object; otherwise it is null. The buf argument is a Buffer containing the generated bytes.
// Asynchronous
const {
randomBytes,
} = await import('node:crypto');
randomBytes(256, (err, buf) => {
if (err) throw err;
console.log(`${buf.length} bytes of random data: ${buf.toString('hex')}`);
});
If the callback function is not provided, the random bytes are generated synchronously and returned as a Buffer. An error will be thrown if there is a problem generating the bytes.
// Synchronous
const {
randomBytes,
} = await import('node:crypto');
const buf = randomBytes(256);
console.log(
`${buf.length} bytes of random data: ${buf.toString('hex')}`);
The crypto.randomBytes() method will not complete until there is sufficient entropy available. This should normally never take longer than a few milliseconds. The only time when generating the random bytes may conceivably block for a longer period of time is right after boot, when the whole system is still low on entropy.
This API uses libuv's threadpool, which can have surprising and negative performance implications for some applications; see the UV_THREADPOOL_SIZE documentation for more information.
The asynchronous version of crypto.randomBytes() is carried out in a single threadpool request. To minimize threadpool task length variation, partition large randomBytes requests when doing so as part of fulfilling a client request.
@since v0.5.8
| Parameter | |
|---|---|
size | The number of bytes to generate. The size must not be larger than 2**31 - 1. |
Returns. if the callback function is not provided.
static member randomBytes (size: float) : NonSharedBuffer
static member randomBytes (size: float) : NonSharedBufferGenerates cryptographically strong pseudorandom data. The size argument is a number indicating the number of bytes to generate.
If a callback function is provided, the bytes are generated asynchronously and the callback function is invoked with two arguments: err and buf. If an error occurs, err will be an Error object; otherwise it is null. The buf argument is a Buffer containing the generated bytes.
// Asynchronous
const {
randomBytes,
} = await import('node:crypto');
randomBytes(256, (err, buf) => {
if (err) throw err;
console.log(`${buf.length} bytes of random data: ${buf.toString('hex')}`);
});
If the callback function is not provided, the random bytes are generated synchronously and returned as a Buffer. An error will be thrown if there is a problem generating the bytes.
// Synchronous
const {
randomBytes,
} = await import('node:crypto');
const buf = randomBytes(256);
console.log(
`${buf.length} bytes of random data: ${buf.toString('hex')}`);
The crypto.randomBytes() method will not complete until there is sufficient entropy available. This should normally never take longer than a few milliseconds. The only time when generating the random bytes may conceivably block for a longer period of time is right after boot, when the whole system is still low on entropy.
This API uses libuv's threadpool, which can have surprising and negative performance implications for some applications; see the UV_THREADPOOL_SIZE documentation for more information.
The asynchronous version of crypto.randomBytes() is carried out in a single threadpool request. To minimize threadpool task length variation, partition large randomBytes requests when doing so as part of fulfilling a client request.
@since v0.5.8
| Parameter | |
|---|---|
size | The number of bytes to generate. The size must not be larger than 2**31 - 1. |
Returns. if the callback function is not provided.
static member randomFill<'T> (buffer: 'T, offset: float, size: float, callback: Callback3<'T>) : unit
static member randomFill<'T> (buffer: 'T, offset: float, size: float, callback: Callback3<'T>) : unitThis function is similar to randomBytes but requires the first argument to be a Buffer that will be filled. It also requires that a callback is passed in.
If the callback function is not provided, an error will be thrown.
import { Buffer } from 'node:buffer';
const { randomFill } = await import('node:crypto');
const buf = Buffer.alloc(10);
randomFill(buf, (err, buf) => {
if (err) throw err;
console.log(buf.toString('hex'));
});
randomFill(buf, 5, (err, buf) => {
if (err) throw err;
console.log(buf.toString('hex'));
});
// The above is equivalent to the following:
randomFill(buf, 5, 5, (err, buf) => {
if (err) throw err;
console.log(buf.toString('hex'));
});
Any ArrayBuffer, TypedArray, or DataView instance may be passed as buffer.
While this includes instances of Float32Array and Float64Array, this function should not be used to generate random floating-point numbers. The result may contain +Infinity, -Infinity, and NaN, and even if the array contains finite numbers only, they are not drawn from a uniform random distribution and have no meaningful lower or upper bounds.
import { Buffer } from 'node:buffer';
const { randomFill } = await import('node:crypto');
const a = new Uint32Array(10);
randomFill(a, (err, buf) => {
if (err) throw err;
console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
.toString('hex'));
});
const b = new DataView(new ArrayBuffer(10));
randomFill(b, (err, buf) => {
if (err) throw err;
console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
.toString('hex'));
});
const c = new ArrayBuffer(10);
randomFill(c, (err, buf) => {
if (err) throw err;
console.log(Buffer.from(buf).toString('hex'));
});
This API uses libuv's threadpool, which can have surprising and negative performance implications for some applications; see the UV_THREADPOOL_SIZE documentation for more information.
The asynchronous version of crypto.randomFill() is carried out in a single threadpool request. To minimize threadpool task length variation, partition large randomFill requests when doing so as part of fulfilling a client request.
@since v7.10.0, v6.13.0
| Parameter | |
|---|---|
buffer | Must be supplied. The size of the provided buffer must not be larger than 2**31 - 1. |
callback | function(err, buf) {}. |
static member randomFill<'T> (buffer: 'T, offset: float, callback: Callback2<'T>) : unit
static member randomFill<'T> (buffer: 'T, offset: float, callback: Callback2<'T>) : unitThis function is similar to randomBytes but requires the first argument to be a Buffer that will be filled. It also requires that a callback is passed in.
If the callback function is not provided, an error will be thrown.
import { Buffer } from 'node:buffer';
const { randomFill } = await import('node:crypto');
const buf = Buffer.alloc(10);
randomFill(buf, (err, buf) => {
if (err) throw err;
console.log(buf.toString('hex'));
});
randomFill(buf, 5, (err, buf) => {
if (err) throw err;
console.log(buf.toString('hex'));
});
// The above is equivalent to the following:
randomFill(buf, 5, 5, (err, buf) => {
if (err) throw err;
console.log(buf.toString('hex'));
});
Any ArrayBuffer, TypedArray, or DataView instance may be passed as buffer.
While this includes instances of Float32Array and Float64Array, this function should not be used to generate random floating-point numbers. The result may contain +Infinity, -Infinity, and NaN, and even if the array contains finite numbers only, they are not drawn from a uniform random distribution and have no meaningful lower or upper bounds.
import { Buffer } from 'node:buffer';
const { randomFill } = await import('node:crypto');
const a = new Uint32Array(10);
randomFill(a, (err, buf) => {
if (err) throw err;
console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
.toString('hex'));
});
const b = new DataView(new ArrayBuffer(10));
randomFill(b, (err, buf) => {
if (err) throw err;
console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
.toString('hex'));
});
const c = new ArrayBuffer(10);
randomFill(c, (err, buf) => {
if (err) throw err;
console.log(Buffer.from(buf).toString('hex'));
});
This API uses libuv's threadpool, which can have surprising and negative performance implications for some applications; see the UV_THREADPOOL_SIZE documentation for more information.
The asynchronous version of crypto.randomFill() is carried out in a single threadpool request. To minimize threadpool task length variation, partition large randomFill requests when doing so as part of fulfilling a client request.
@since v7.10.0, v6.13.0
| Parameter | |
|---|---|
buffer | Must be supplied. The size of the provided buffer must not be larger than 2**31 - 1. |
callback | function(err, buf) {}. |
static member randomFill<'T> (buffer: 'T, callback: Callback<'T>) : unit
static member randomFill<'T> (buffer: 'T, callback: Callback<'T>) : unitThis function is similar to randomBytes but requires the first argument to be a Buffer that will be filled. It also requires that a callback is passed in.
If the callback function is not provided, an error will be thrown.
import { Buffer } from 'node:buffer';
const { randomFill } = await import('node:crypto');
const buf = Buffer.alloc(10);
randomFill(buf, (err, buf) => {
if (err) throw err;
console.log(buf.toString('hex'));
});
randomFill(buf, 5, (err, buf) => {
if (err) throw err;
console.log(buf.toString('hex'));
});
// The above is equivalent to the following:
randomFill(buf, 5, 5, (err, buf) => {
if (err) throw err;
console.log(buf.toString('hex'));
});
Any ArrayBuffer, TypedArray, or DataView instance may be passed as buffer.
While this includes instances of Float32Array and Float64Array, this function should not be used to generate random floating-point numbers. The result may contain +Infinity, -Infinity, and NaN, and even if the array contains finite numbers only, they are not drawn from a uniform random distribution and have no meaningful lower or upper bounds.
import { Buffer } from 'node:buffer';
const { randomFill } = await import('node:crypto');
const a = new Uint32Array(10);
randomFill(a, (err, buf) => {
if (err) throw err;
console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
.toString('hex'));
});
const b = new DataView(new ArrayBuffer(10));
randomFill(b, (err, buf) => {
if (err) throw err;
console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
.toString('hex'));
});
const c = new ArrayBuffer(10);
randomFill(c, (err, buf) => {
if (err) throw err;
console.log(Buffer.from(buf).toString('hex'));
});
This API uses libuv's threadpool, which can have surprising and negative performance implications for some applications; see the UV_THREADPOOL_SIZE documentation for more information.
The asynchronous version of crypto.randomFill() is carried out in a single threadpool request. To minimize threadpool task length variation, partition large randomFill requests when doing so as part of fulfilling a client request.
@since v7.10.0, v6.13.0
| Parameter | |
|---|---|
buffer | Must be supplied. The size of the provided buffer must not be larger than 2**31 - 1. |
callback | function(err, buf) {}. |
static member randomFillSync<'T> (buffer: 'T, ?offset: float, ?size: float) : 'T
static member randomFillSync<'T> (buffer: 'T, ?offset: float, ?size: float) : 'TSynchronous version of randomFill.
import { Buffer } from 'node:buffer';
const { randomFillSync } = await import('node:crypto');
const buf = Buffer.alloc(10);
console.log(randomFillSync(buf).toString('hex'));
randomFillSync(buf, 5);
console.log(buf.toString('hex'));
// The above is equivalent to the following:
randomFillSync(buf, 5, 5);
console.log(buf.toString('hex'));
Any ArrayBuffer, TypedArray or DataView instance may be passed asbuffer.
import { Buffer } from 'node:buffer';
const { randomFillSync } = await import('node:crypto');
const a = new Uint32Array(10);
console.log(Buffer.from(randomFillSync(a).buffer,
a.byteOffset, a.byteLength).toString('hex'));
const b = new DataView(new ArrayBuffer(10));
console.log(Buffer.from(randomFillSync(b).buffer,
b.byteOffset, b.byteLength).toString('hex'));
const c = new ArrayBuffer(10);
console.log(Buffer.from(randomFillSync(c)).toString('hex'));
@since v7.10.0, v6.13.0
| Parameter | |
|---|---|
buffer | Must be supplied. The size of the provided buffer must not be larger than 2**31 - 1. |
Returns. The object passed as buffer argument.
static member randomInt (min: float, max: float, callback: Callback2) : unit
static member randomInt (min: float, max: float, callback: Callback2) : unitReturn a random integer n such that min <= n < max. This implementation avoids modulo bias.
The range (max - min) must be less than 2**48. min and max must be safe integers.
If the callback function is not provided, the random integer is generated synchronously.
// Asynchronous
const {
randomInt,
} = await import('node:crypto');
randomInt(3, (err, n) => {
if (err) throw err;
console.log(`Random number chosen from (0, 1, 2): ${n}`);
});
// Synchronous
const {
randomInt,
} = await import('node:crypto');
const n = randomInt(3);
console.log(`Random number chosen from (0, 1, 2): ${n}`);
// With `min` argument
const {
randomInt,
} = await import('node:crypto');
const n = randomInt(1, 7);
console.log(`The dice rolled: ${n}`);
@since v14.10.0, v12.19.0
| Parameter | |
|---|---|
min | Start of random range (inclusive). |
max | End of random range (exclusive). |
callback | function(err, n) {}. |
static member randomInt (max: float, callback: Callback) : unit
static member randomInt (max: float, callback: Callback) : unitReturn a random integer n such that min <= n < max. This implementation avoids modulo bias.
The range (max - min) must be less than 2**48. min and max must be safe integers.
If the callback function is not provided, the random integer is generated synchronously.
// Asynchronous
const {
randomInt,
} = await import('node:crypto');
randomInt(3, (err, n) => {
if (err) throw err;
console.log(`Random number chosen from (0, 1, 2): ${n}`);
});
// Synchronous
const {
randomInt,
} = await import('node:crypto');
const n = randomInt(3);
console.log(`Random number chosen from (0, 1, 2): ${n}`);
// With `min` argument
const {
randomInt,
} = await import('node:crypto');
const n = randomInt(1, 7);
console.log(`The dice rolled: ${n}`);
@since v14.10.0, v12.19.0
| Parameter | |
|---|---|
min | Start of random range (inclusive). |
max | End of random range (exclusive). |
callback | function(err, n) {}. |
static member randomInt (min: float, max: float) : float
static member randomInt (min: float, max: float) : floatReturn a random integer n such that min <= n < max. This implementation avoids modulo bias.
The range (max - min) must be less than 2**48. min and max must be safe integers.
If the callback function is not provided, the random integer is generated synchronously.
// Asynchronous
const {
randomInt,
} = await import('node:crypto');
randomInt(3, (err, n) => {
if (err) throw err;
console.log(`Random number chosen from (0, 1, 2): ${n}`);
});
// Synchronous
const {
randomInt,
} = await import('node:crypto');
const n = randomInt(3);
console.log(`Random number chosen from (0, 1, 2): ${n}`);
// With `min` argument
const {
randomInt,
} = await import('node:crypto');
const n = randomInt(1, 7);
console.log(`The dice rolled: ${n}`);
@since v14.10.0, v12.19.0
| Parameter | |
|---|---|
min | Start of random range (inclusive). |
max | End of random range (exclusive). |
callback | function(err, n) {}. |
static member randomInt (max: float) : float
static member randomInt (max: float) : floatReturn a random integer n such that min <= n < max. This implementation avoids modulo bias.
The range (max - min) must be less than 2**48. min and max must be safe integers.
If the callback function is not provided, the random integer is generated synchronously.
// Asynchronous
const {
randomInt,
} = await import('node:crypto');
randomInt(3, (err, n) => {
if (err) throw err;
console.log(`Random number chosen from (0, 1, 2): ${n}`);
});
// Synchronous
const {
randomInt,
} = await import('node:crypto');
const n = randomInt(3);
console.log(`Random number chosen from (0, 1, 2): ${n}`);
// With `min` argument
const {
randomInt,
} = await import('node:crypto');
const n = randomInt(1, 7);
console.log(`The dice rolled: ${n}`);
@since v14.10.0, v12.19.0
| Parameter | |
|---|---|
min | Start of random range (inclusive). |
max | End of random range (exclusive). |
callback | function(err, n) {}. |
static member randomUUID (?options: RandomUUIDOptions) : string
static member randomUUID (?options: RandomUUIDOptions) : stringGenerates a random RFC 4122 version 4 UUID. The UUID is generated using a cryptographic pseudorandom number generator.
@since v15.6.0, v14.17.0
static member scrypt (password: BinaryLike, salt: BinaryLike, keylen: float, options: ScryptOptions, callback: Callback2) : unit
static member scrypt (password: BinaryLike, salt: BinaryLike, keylen: float, options: ScryptOptions, callback: Callback2) : unitProvides an asynchronous scrypt implementation. Scrypt is a password-based key derivation function that is designed to be expensive computationally and memory-wise in order to make brute-force attacks unrewarding.
The salt should be as unique as possible. It is recommended that a salt is random and at least 16 bytes long. See NIST SP 800-132 for details.
When passing strings for password or salt, please consider caveats when using strings as inputs to cryptographic APIs.
The callback function is called with two arguments: err and derivedKey. err is an exception object when key derivation fails, otherwise err is null. derivedKey is passed to the callback as a Buffer.
An exception is thrown when any of the input arguments specify invalid values or types.
const {
scrypt,
} = await import('node:crypto');
// Using the factory defaults.
scrypt('password', 'salt', 64, (err, derivedKey) => {
if (err) throw err;
console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
});
// Using a custom N parameter. Must be a power of two.
scrypt('password', 'salt', 64, { N: 1024 }, (err, derivedKey) => {
if (err) throw err;
console.log(derivedKey.toString('hex')); // '3745e48...aa39b34'
});
@since v10.5.0
static member scrypt (password: BinaryLike, salt: BinaryLike, keylen: float, callback: Callback) : unit
static member scrypt (password: BinaryLike, salt: BinaryLike, keylen: float, callback: Callback) : unitProvides an asynchronous scrypt implementation. Scrypt is a password-based key derivation function that is designed to be expensive computationally and memory-wise in order to make brute-force attacks unrewarding.
The salt should be as unique as possible. It is recommended that a salt is random and at least 16 bytes long. See NIST SP 800-132 for details.
When passing strings for password or salt, please consider caveats when using strings as inputs to cryptographic APIs.
The callback function is called with two arguments: err and derivedKey. err is an exception object when key derivation fails, otherwise err is null. derivedKey is passed to the callback as a Buffer.
An exception is thrown when any of the input arguments specify invalid values or types.
const {
scrypt,
} = await import('node:crypto');
// Using the factory defaults.
scrypt('password', 'salt', 64, (err, derivedKey) => {
if (err) throw err;
console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
});
// Using a custom N parameter. Must be a power of two.
scrypt('password', 'salt', 64, { N: 1024 }, (err, derivedKey) => {
if (err) throw err;
console.log(derivedKey.toString('hex')); // '3745e48...aa39b34'
});
@since v10.5.0
static member scryptSync (password: BinaryLike, salt: BinaryLike, keylen: float, ?options: ScryptOptions) : NonSharedBuffer
static member scryptSync (password: BinaryLike, salt: BinaryLike, keylen: float, ?options: ScryptOptions) : NonSharedBufferProvides a synchronous scrypt implementation. Scrypt is a password-based key derivation function that is designed to be expensive computationally and memory-wise in order to make brute-force attacks unrewarding.
The salt should be as unique as possible. It is recommended that a salt is random and at least 16 bytes long. See NIST SP 800-132 for details.
When passing strings for password or salt, please consider caveats when using strings as inputs to cryptographic APIs.
An exception is thrown when key derivation fails, otherwise the derived key is returned as a Buffer.
An exception is thrown when any of the input arguments specify invalid values or types.
const {
scryptSync,
} = await import('node:crypto');
// Using the factory defaults.
const key1 = scryptSync('password', 'salt', 64);
console.log(key1.toString('hex')); // '3745e48...08d59ae'
// Using a custom N parameter. Must be a power of two.
const key2 = scryptSync('password', 'salt', 64, { N: 1024 });
console.log(key2.toString('hex')); // '3745e48...aa39b34'
@since v10.5.0
static member secureHeapUsed () : SecureHeapUsage
static member secureHeapUsed () : SecureHeapUsage@since v15.6.0
static member setEngine (engine: string, ?flags: float) : unit
static member setEngine (engine: string, ?flags: float) : unitLoad and set the engine for some or all OpenSSL functions (selected by flags).
engine could be either an id or a path to the engine's shared library.
The optional flags argument uses ENGINE_METHOD_ALL by default. The flags is a bit field taking one of or a mix of the following flags (defined in crypto.constants):
crypto.constants.ENGINE_METHOD_RSAcrypto.constants.ENGINE_METHOD_DSAcrypto.constants.ENGINE_METHOD_DHcrypto.constants.ENGINE_METHOD_RANDcrypto.constants.ENGINE_METHOD_ECcrypto.constants.ENGINE_METHOD_CIPHERScrypto.constants.ENGINE_METHOD_DIGESTScrypto.constants.ENGINE_METHOD_PKEY_METHScrypto.constants.ENGINE_METHOD_PKEY_ASN1_METHScrypto.constants.ENGINE_METHOD_ALLcrypto.constants.ENGINE_METHOD_NONE
@since v0.11.11
static member sign (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,SignJsonWebKeyInput,SignKeyObjectInput,SignPrivateKeyInput>, callback: Callback) : unit
static member sign (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,SignJsonWebKeyInput,SignKeyObjectInput,SignPrivateKeyInput>, callback: Callback) : unitCalculates and returns the signature for data using the given private key and algorithm. If algorithm is null or undefined, then the algorithm is dependent upon the key type (especially Ed25519 and Ed448).
If key is not a KeyObject, this function behaves as if key had been passed to createPrivateKey. If it is an object, the following additional properties can be passed:
If the callback function is provided this function uses libuv's threadpool.
@since v12.0.0
static member sign (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,SignJsonWebKeyInput,SignKeyObjectInput,SignPrivateKeyInput>) : NonSharedBuffer
static member sign (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,SignJsonWebKeyInput,SignKeyObjectInput,SignPrivateKeyInput>) : NonSharedBufferCalculates and returns the signature for data using the given private key and algorithm. If algorithm is null or undefined, then the algorithm is dependent upon the key type (especially Ed25519 and Ed448).
If key is not a KeyObject, this function behaves as if key had been passed to createPrivateKey. If it is an object, the following additional properties can be passed:
If the callback function is provided this function uses libuv's threadpool.
@since v12.0.0
static member timingSafeEqual (a: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, b: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : bool
static member timingSafeEqual (a: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, b: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : boolThis function compares the underlying bytes that represent the given ArrayBuffer, TypedArray, or DataView instances using a constant-time algorithm.
This function does not leak timing information that would allow an attacker to guess one of the values. This is suitable for comparing HMAC digests or secret values like authentication cookies or capability urls.
a and b must both be Buffers, TypedArrays, or DataViews, and they must have the same byte length. An error is thrown if a and b have different byte lengths.
If at least one of a and b is a TypedArray with more than one byte per entry, such as Uint16Array, the result will be computed using the platform byte order.
When both of the inputs are Float32Arrays or Float64Arrays, this function might return unexpected results due to IEEE 754encoding of floating-point numbers. In particular, neither x === y nor Object.is(x, y) implies that the byte representations of two floating-pointnumbers x and y are equal.
Use of crypto.timingSafeEqual does not guarantee that the surrounding code is timing-safe. Care should be taken to ensure that the surrounding code does not introduce timing vulnerabilities.
@since v6.6.0
static member verify (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,VerifyJsonWebKeyInput,VerifyKeyObjectInput,VerifyPublicKeyInput>, signature: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, callback: Callback) : unit
static member verify (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,VerifyJsonWebKeyInput,VerifyKeyObjectInput,VerifyPublicKeyInput>, signature: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, callback: Callback) : unitVerifies the given signature for data using the given key and algorithm. If algorithm is null or undefined, then the algorithm is dependent upon the key type (especially Ed25519 and Ed448).
If key is not a KeyObject, this function behaves as if key had been passed to createPublicKey. If it is an object, the following additional properties can be passed:
The signature argument is the previously calculated signature for the data.
Because public keys can be derived from private keys, a private key or a public key may be passed for key.
If the callback function is provided this function uses libuv's threadpool.
@since v12.0.0
static member verify (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,VerifyJsonWebKeyInput,VerifyKeyObjectInput,VerifyPublicKeyInput>, signature: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : bool
static member verify (algorithm: string option, data: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, key: U6<string,Buffer<U2<ArrayBuffer,SharedArrayBuffer>>,KeyObject,VerifyJsonWebKeyInput,VerifyKeyObjectInput,VerifyPublicKeyInput>, signature: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : boolVerifies the given signature for data using the given key and algorithm. If algorithm is null or undefined, then the algorithm is dependent upon the key type (especially Ed25519 and Ed448).
If key is not a KeyObject, this function behaves as if key had been passed to createPublicKey. If it is an object, the following additional properties can be passed:
The signature argument is the previously calculated signature for the data.
Because public keys can be derived from private keys, a private key or a public key may be passed for key.
If the callback function is provided this function uses libuv's threadpool.
@since v12.0.0