js-crypto-aes
Version:
Universal Module for AES Encryption and Decryption in JavaScript
49 lines (48 loc) • 2.64 kB
TypeScript
/**
* aes.js
*/
import { cipherOptions } from './params';
/**
* Encrypt data with AES
* @param {Uint8Array} msg - Message to be encrypted.
* @param {Uint8Array} key - The symmetric key used to encrypt the message.
* @param {String} [name = 'AES-GCM'] - Name of the specified algorithm like 'AES-GCM'.
* @param {Uint8Array} [iv] - Byte array of the initial vector if required.
* @param {Uint8Array} [additionalData = new Uint8Array([])] - Byte array of additional data if required.
* @param {Number} [tagLength = params.ciphers[name].tagLength] - Authentication tag length if required.
* @return {Promise<Uint8Array>} - Encrypted message.
* @throws {Error} - Throws if InvalidArguments, FaildToEncryptWeb/Node, or UnsupportedEnvironment (no webcrypto/nodecrypto).
*/
export declare const encrypt: (msg: Uint8Array, key: Uint8Array, { name, iv, additionalData, tagLength }: cipherOptions) => Promise<Uint8Array>;
/**
* Decrypt data with AES
* @param {Uint8Array} data - Byte array of encrypted data.
* @param {Uint8Array} key - Byte array of symmetric key to be used for decryption.
* @param {String} [name = 'AES-GCM'] - Name of the specified algorithm like 'AES-GCM'.
* @param {Uint8Array} [iv] - Byte array of the initial vector if required.
* @param {Uint8Array} [additionalData = new Uint8Array([])] - Byte array of additional data if required.
* @param {Number} [tagLength = params.ciphers[name].tagLength] - Authentication tag length if required.
* @return {Promise<Uint8Array>} - Decrypted plaintext message.
* @throws {Error} - Throws if InvalidArguments, FailedToDecryptWeb/Node, or UnsupportedEnvironment (no webcrypto/nodecrypto).
*/
export declare const decrypt: (data: Uint8Array, key: Uint8Array, { name, iv, additionalData, tagLength }: cipherOptions) => Promise<Uint8Array>;
/**
* AES-KW wrapping
* @param keyToBeWrapped {Uint8Array} - key bytes to be wrapped
* @param wrappingKey {Uint8Array} - wrapping key encryption key
* @param name {'AES-KW'} - this is simply for future extension
* @return {Promise<Uint8Array>} - output wrapped key
*/
export declare const wrapKey: (keyToBeWrapped: Uint8Array, wrappingKey: Uint8Array, { name }: {
name: 'AES-KW';
}) => Promise<Uint8Array>;
/**
* AES-KW unwrapping
* @param wrappedKey {Uint8Array} - wrapped key bytes
* @param wrappingKey {Uint8Array} - wrapping key encryption key
* @param name {'AES-KW'} - this is simply for future extension
* @return {Promise<Uint8Array>} - output unwrapped key
*/
export declare const unwrapKey: (wrappedKey: Uint8Array, wrappingKey: Uint8Array, { name }: {
name: 'AES-KW';
}) => Promise<Uint8Array>;