js-crypto-aes
Version:
Universal Module for AES Encryption and Decryption in JavaScript
59 lines (58 loc) • 2.97 kB
TypeScript
/**
* nodeapi.js
*/
import { cipherOptions } from './params';
/**
* Node.js KeyWrapping function simply uses encrypt function.
* @param keyToBeWrapped {Uint8Array} - plaintext key
* @param wrappingKey {Uint8Array} - wrapping key
* @param name {string} - 'AES-KW'
* @param iv {Uint8Array} - default is '0xA6A6A6A6A6A6A6A6'
* @param nodeCrypto {Object} - NodeCrypto object
* @return {Uint8Array} - Unwrapped Key
*/
export declare const wrapKey: (keyToBeWrapped: Uint8Array, wrappingKey: Uint8Array, { name, iv }: {
name: 'AES-KW';
iv: Uint8Array;
}, nodeCrypto: any) => Uint8Array;
/**
* Node.js KeyUnwrapping function as well as keyWrapping
* @param wrappedKey {Uint8Array} - Wrapped key
* @param unwrappingKey {Uint8Array} - Key used for wrapping
* @param name {string} - 'AES-KW'
* @param iv {Uint8Array} - default is '0xA6A6A6A6A6A6A6A6'
* @param nodeCrypto {Object} - NodeCrypto object
* @return {Uint8Array} - Unwrapped Key
*/
export declare const unwrapKey: (wrappedKey: Uint8Array, unwrappingKey: Uint8Array, { name, iv }: {
name: 'AES-KW';
iv: Uint8Array;
}, nodeCrypto: any) => Uint8Array;
/**
* Encrypt plaintext message via AES Node.js crypto API
* @param {Uint8Array} msg - Plaintext message to be encrypted.
* @param {Uint8Array} key - Byte array of symmetric key.
* @param {String} name - Name of AES algorithm like 'AES-GCM'.
* @param {Uint8Array} [iv] - Byte array of initial vector if required.
* @param {Uint8Array} [additionalData] - Byte array of additional data if required.
* @param {Number} [tagLength] - Authentication tag length if required.
* @param {Object} nodeCrypto - NodeCrypto object, i.e., require(crypto) in Node.js.
* @param wrapKey {Boolean} [false] - true if called as AES-KW
* @return {Uint8Array} - Encrypted message byte array.
* @throws {Error} - Throws error if UnsupportedCipher.
*/
export declare const encrypt: (msg: Uint8Array, key: Uint8Array, { name, iv, additionalData, tagLength }: cipherOptions, nodeCrypto: any, wrapKey?: boolean) => Uint8Array;
/**
* Decrypt data through AES Node.js crypto API.
* @param {Uint8Array} data - Encrypted message to be decrypted.
* @param {Uint8Array} key - Byte array of symmetric key.
* @param {String} name - Name of AES algorithm like 'AES-GCM'.
* @param {Uint8Array} [iv] - Byte array of initial vector if required.
* @param {Uint8Array} [additionalData] - Byte array of additional data if required.
* @param {Number} [tagLength] - Authentication tag length if required.
* @param {Object} nodeCrypto - NodeCrypto object, i.e., require(crypto) in Node.js.
* @return {Uint8Array} - Decrypted message byte array.
* @param unwrapKey {Boolean} [false] - true if called as AES-KW
* @throws {Error} - Throws error if UnsupportedCipher or DecryptionFailure.
*/
export declare const decrypt: (data: Uint8Array, key: Uint8Array, { name, iv, additionalData, tagLength }: cipherOptions, nodeCrypto: any, unwrapKey?: boolean) => Uint8Array;