aes-universal-node
Version:
Node.js implementation of aes-universal
100 lines (91 loc) • 3.96 kB
TypeScript
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';
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 {
constructor();
}
export declare const nodeAesCipher: NodeAesCipher;
/**
* Node.js implementation of CBC cipher using crypto module
*/
export declare class NodeCbcCipher extends AbstractCbcCipher {
/**
* 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 {
/**
* 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: (size?: number) => Uint8Array;
export { }