UNPKG

aes-universal-node

Version:
115 lines (107 loc) 4.62 kB
import { AbstractCbcCipher } from 'aes-universal'; import { AbstractGcmCipher } from 'aes-universal'; import { AesCipher } from 'aes-universal'; import { CbcDecryptInternalParams } from 'aes-universal'; import { CbcEncryptInternalParams } from 'aes-universal'; import { GcmDecryptInternalParams } from 'aes-universal'; import { GcmEncryptInternalParams } from 'aes-universal'; import { GcmEncryptInternalResult } from 'aes-universal'; import { GenerateTagParams } from 'aes-universal'; import { RandomBytes } from 'aes-universal'; export declare type GCMType = 'aes-128-gcm' | 'aes-192-gcm' | 'aes-256-gcm'; /** * Converts a key bit length to the corresponding AES-GCM cipher type. * * @param keyBitLength - The length of the key in bits. Must be one of: 128, 192, or 256. * @returns The corresponding AES-GCM cipher type as a string literal. * @throws {Error} When the key bit length is not 128, 192, or 256. * @example * const cipherType = keyBitLengthToGCMType(128); // 'aes-128-gcm' */ export declare const keyBitLengthToGCMType: (keyBitLength: number) => GCMType; /** * Node.js implementation of the AES cipher using Node.js crypto module. * * This class extends the base AesCipher class and provides implementations * for both CBC and GCM modes using Node.js native crypto functionality. */ export declare class NodeAesCipher extends AesCipher<NodeCbcCipher, typeof NodeCbcCipher, NodeGcmCipher, typeof NodeGcmCipher> { /** * Creates a new instance of NodeAesCipher. * * @param randomBytes - Function that generates cryptographically secure random bytes * Must implement the RandomBytes interface from aes-universal */ constructor(randomBytes: RandomBytes); } /** * Node.js implementation of CBC cipher using crypto module */ export declare class NodeCbcCipher extends AbstractCbcCipher { /** * Creates a new NodeCbcCipher instance * @param randomBytes - Function to generate random bytes */ constructor(randomBytes: RandomBytes); /** * Encrypts data using AES-CBC * @param encRawKey - Raw encryption key * @param iv - Initialization vector * @param plaintext - Data to encrypt * @returns Encrypted data as Uint8Array */ encryptInternal: ({ encRawKey, iv, plaintext, }: CbcEncryptInternalParams) => Promise<Uint8Array>; /** * Decrypts data using AES-CBC * @param encRawKey - Raw encryption key * @param iv - Initialization vector * @param ciphertext - Data to decrypt * @returns Decrypted data as Uint8Array */ decryptInternal: ({ encRawKey, iv, ciphertext, }: CbcDecryptInternalParams) => Promise<Uint8Array>; /** * Generates an HMAC tag for message authentication * @param macRawKey - Raw key for HMAC * @param macData - Data to authenticate * @param keyBitLength - The length of the key in bits * @returns HMAC tag as Uint8Array */ generateTag: ({ macRawKey, macData, keyBitLength, }: GenerateTagParams) => Promise<Uint8Array>; } /** * Node.js implementation of GCM cipher using crypto module */ export declare class NodeGcmCipher extends AbstractGcmCipher { /** * Creates a new NodeGcmCipher instance * @param randomBytes - Function to generate random bytes */ constructor(randomBytes: RandomBytes); /** * Encrypts data using AES-GCM * @param encRawKey - Raw encryption key * @param iv - Initialization vector * @param plaintext - Data to encrypt * @param aad - Additional authenticated data * @returns Object containing ciphertext and authentication tag */ encryptInternal: ({ encRawKey, iv, plaintext, aad, }: GcmEncryptInternalParams) => Promise<GcmEncryptInternalResult>; /** * Decrypts data using AES-GCM * @param encRawKey - Raw encryption key * @param iv - Initialization vector * @param ciphertext - Data to decrypt * @param tag - Authentication tag * @param aad - Additional authenticated data * @returns Decrypted data as Uint8Array */ decryptInternal: ({ encRawKey, iv, ciphertext, tag, aad, }: GcmDecryptInternalParams) => Promise<Uint8Array>; } /** * Generates cryptographically secure random bytes using Node.js crypto module. * * @param {number} [size=32] - The number of bytes to generate. Defaults to 32. * @returns {Uint8Array} - A Uint8Array containing the generated random bytes. */ export declare const nodeRandomBytes: RandomBytes; export { }