| | |
| | | * // Prints: |
| | | * // c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e |
| | | * ``` |
| | | * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/crypto.js) |
| | | * @see [source](https://github.com/nodejs/node/blob/v17.0.0/lib/crypto.js) |
| | | */ |
| | | declare module 'crypto' { |
| | | import * as stream from 'node:stream'; |
| | |
| | | */ |
| | | function createHmac(algorithm: string, key: BinaryLike | KeyObject, options?: stream.TransformOptions): Hmac; |
| | | // https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings |
| | | type BinaryToTextEncoding = 'base64' | 'base64url' | 'hex'; |
| | | type BinaryToTextEncoding = 'base64' | 'base64url' | 'hex' | 'binary'; |
| | | type CharacterEncoding = 'utf8' | 'utf-8' | 'utf16le' | 'latin1'; |
| | | type LegacyCharacterEncoding = 'ascii' | 'binary' | 'ucs2' | 'ucs-2'; |
| | | type Encoding = BinaryToTextEncoding | CharacterEncoding | LegacyCharacterEncoding; |
| | |
| | | } |
| | | type CipherCCMTypes = 'aes-128-ccm' | 'aes-192-ccm' | 'aes-256-ccm' | 'chacha20-poly1305'; |
| | | type CipherGCMTypes = 'aes-128-gcm' | 'aes-192-gcm' | 'aes-256-gcm'; |
| | | type CipherOCBTypes = 'aes-128-ocb' | 'aes-192-ocb' | 'aes-256-ocb'; |
| | | type BinaryLike = string | NodeJS.ArrayBufferView; |
| | | type CipherKey = BinaryLike | KeyObject; |
| | | interface CipherCCMOptions extends stream.TransformOptions { |
| | |
| | | } |
| | | interface CipherGCMOptions extends stream.TransformOptions { |
| | | authTagLength?: number | undefined; |
| | | } |
| | | interface CipherOCBOptions extends stream.TransformOptions { |
| | | authTagLength: number; |
| | | } |
| | | /** |
| | | * Creates and returns a `Cipher` object that uses the given `algorithm` and`password`. |
| | |
| | | * @since v0.1.94 |
| | | * @param options `stream.transform` options |
| | | */ |
| | | function createCipheriv(algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike | null, options: CipherCCMOptions): CipherCCM; |
| | | function createCipheriv(algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike | null, options?: CipherGCMOptions): CipherGCM; |
| | | function createCipheriv(algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike, options: CipherCCMOptions): CipherCCM; |
| | | function createCipheriv(algorithm: CipherOCBTypes, key: CipherKey, iv: BinaryLike, options: CipherOCBOptions): CipherOCB; |
| | | function createCipheriv(algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike, options?: CipherGCMOptions): CipherGCM; |
| | | function createCipheriv(algorithm: string, key: CipherKey, iv: BinaryLike | null, options?: stream.TransformOptions): Cipher; |
| | | /** |
| | | * Instances of the `Cipher` class are used to encrypt data. The class can be |
| | |
| | | ): this; |
| | | getAuthTag(): Buffer; |
| | | } |
| | | interface CipherOCB extends Cipher { |
| | | setAAD( |
| | | buffer: NodeJS.ArrayBufferView, |
| | | options?: { |
| | | plaintextLength: number; |
| | | } |
| | | ): this; |
| | | getAuthTag(): Buffer; |
| | | } |
| | | /** |
| | | * Creates and returns a `Decipher` object that uses the given `algorithm` and`password` (key). |
| | | * |
| | |
| | | * @since v0.1.94 |
| | | * @param options `stream.transform` options |
| | | */ |
| | | function createDecipheriv(algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike | null, options: CipherCCMOptions): DecipherCCM; |
| | | function createDecipheriv(algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike | null, options?: CipherGCMOptions): DecipherGCM; |
| | | function createDecipheriv(algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike, options: CipherCCMOptions): DecipherCCM; |
| | | function createDecipheriv(algorithm: CipherOCBTypes, key: CipherKey, iv: BinaryLike, options: CipherOCBOptions): DecipherOCB; |
| | | function createDecipheriv(algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike, options?: CipherGCMOptions): DecipherGCM; |
| | | function createDecipheriv(algorithm: string, key: CipherKey, iv: BinaryLike | null, options?: stream.TransformOptions): Decipher; |
| | | /** |
| | | * Instances of the `Decipher` class are used to decrypt data. The class can be |
| | |
| | | ): this; |
| | | } |
| | | interface DecipherGCM extends Decipher { |
| | | setAuthTag(buffer: NodeJS.ArrayBufferView): this; |
| | | setAAD( |
| | | buffer: NodeJS.ArrayBufferView, |
| | | options?: { |
| | | plaintextLength: number; |
| | | } |
| | | ): this; |
| | | } |
| | | interface DecipherOCB extends Decipher { |
| | | setAuthTag(buffer: NodeJS.ArrayBufferView): this; |
| | | setAAD( |
| | | buffer: NodeJS.ArrayBufferView, |
| | |
| | | /** |
| | | * Generates a random [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) version 4 UUID. The UUID is generated using a |
| | | * cryptographic pseudorandom number generator. |
| | | * @since v15.6.0 |
| | | * @since v15.6.0, v14.17.0 |
| | | */ |
| | | function randomUUID(options?: RandomUUIDOptions): string; |
| | | interface X509CheckOptions { |
| | |
| | | */ |
| | | readonly fingerprint256: string; |
| | | /** |
| | | * The SHA-512 fingerprint of this certificate. |
| | | * @since v16.14.0 |
| | | */ |
| | | readonly fingerprint512: string; |
| | | /** |
| | | * The complete subject of this certificate. |
| | | * @since v15.6.0 |
| | | */ |
| | | readonly subject: string; |
| | | /** |
| | | * The subject alternative name specified for this certificate. |
| | | * The subject alternative name specified for this certificate or `undefined` |
| | | * if not available. |
| | | * @since v15.6.0 |
| | | */ |
| | | readonly subjectAltName: string; |
| | | readonly subjectAltName: string | undefined; |
| | | /** |
| | | * The information access content of this certificate. |
| | | * The information access content of this certificate or `undefined` if not |
| | | * available. |
| | | * @since v15.6.0 |
| | | */ |
| | | readonly infoAccess: string; |
| | | readonly infoAccess: string | undefined; |
| | | /** |
| | | * An array detailing the key usages for this certificate. |
| | | * @since v15.6.0 |
| | |
| | | * @since v15.6.0 |
| | | * @return Returns `email` if the certificate matches, `undefined` if it does not. |
| | | */ |
| | | checkEmail(email: string, options?: X509CheckOptions): string | undefined; |
| | | checkEmail(email: string, options?: Pick<X509CheckOptions, 'subject'>): string | undefined; |
| | | /** |
| | | * Checks whether the certificate matches the given host name. |
| | | * @since v15.6.0 |
| | |
| | | * @since v15.6.0 |
| | | * @return Returns `ip` if the certificate matches, `undefined` if it does not. |
| | | */ |
| | | checkIP(ip: string, options?: X509CheckOptions): string | undefined; |
| | | checkIP(ip: string): string | undefined; |
| | | /** |
| | | * Checks whether this certificate was issued by the given `otherCert`. |
| | | * @since v15.6.0 |