UNPKG

aes-ctr-concurrent

Version:

Native TypeScript Node.js library for AES-256-CTR, enabling concurrent encryption/decryption with precise IV offset handling down to any byte level, not just full blocks.

27 lines (26 loc) 1.73 kB
import crypto from "crypto"; /** * Creates a `crypto.Cipher` instance using the AES-256-CTR algorithm for encrypting data. * * @param {Buffer} key - a 32-byte encryption key. * @param {Buffer} iv - a 16-byte initialization vector (IV). * @param {number | bigint} [startPositionInBytes=0n] - optional start position in bytes for the encryption process. * This allows you to set the encryption position precisely, even within a block. * @returns {crypto.Cipher} A `Cipher` object ready to encrypt data. * @throws {AesCtrConcurrentError} Throws an error if any of the parameters are invalid. */ export declare function createCipher(key: Buffer, iv: Buffer, startPositionInBytes?: number): crypto.Cipher; export declare function createCipher(key: Buffer, iv: Buffer, startPositionInBytes?: bigint): crypto.Cipher; /** * Creates a `crypto.Decipher` instance using the AES-256-CTR algorithm for decrypting data. * * @param {Buffer} key - a 32-byte decryption key. * @param {Buffer} iv - a 16-byte initialization vector (IV). * @param {number | bigint} [startPositionInBytes=0n] - optional start position in bytes for the decryption process. * This allows you to set the decryption position precisely, even within a block. * @returns {crypto.Decipher} A `Decipher` object ready to decrypt data. * @throws {AesCtrConcurrentError} Throws an error if any of the parameters are invalid. */ export declare function createDecipher(key: Buffer, iv: Buffer, startPositionInBytes?: number): crypto.Cipher; export declare function createDecipher(key: Buffer, iv: Buffer, startPositionInBytes?: bigint): crypto.Cipher; export declare function incrementIvByFullBlocks(originalIv: Buffer, fullBlocksToIncrement: bigint): Buffer;