js-crypto-aes
Version:
Universal Module for AES Encryption and Decryption in JavaScript
57 lines (56 loc) • 2.82 kB
TypeScript
/**
* webapi.js
*/
import { cipherOptions } from './params';
/**
* WebCrypto 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 webCrypto {Object} - crypto.subtle object
* @return {Uint8Array} - Unwrapped Key
*/
export declare const wrapKey: (keyToBeWrapped: Uint8Array, wrappingKey: Uint8Array, { name, iv }: {
name: 'AES-KW';
iv: Uint8Array;
}, webCrypto: any) => Promise<Uint8Array>;
/**
* WebCrypto 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 webCrypto {Object} - crypto.subtle object
* @return {Uint8Array} - Unwrapped Key
*/
export declare const unwrapKey: (wrappedKey: Uint8Array, unwrappingKey: Uint8Array, { name, iv }: {
name: 'AES-KW';
iv: Uint8Array;
}, webCrypto: any) => Promise<Uint8Array>;
/**
* Encrypt data through AES of WebCrypto 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} webCrypto - WebCrypto object, i.e., window.crypto.subtle
* @return {Promise<Uint8Array>} - Encrypted data byte array.
* @throws {Error} - Throws if UnsupportedCipher.
*/
export declare const encrypt: (msg: Uint8Array, key: Uint8Array, { name, iv, additionalData, tagLength }: cipherOptions, webCrypto: any) => Promise<Uint8Array>;
/**
* Decrypt data through AES of WebCrypto 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} webCrypto - WebCrypto object, i.e., window.crypto.subtle
* @return {Promise<Uint8Array>} - Decrypted plaintext message.
* @throws {Error} - Throws if UnsupportedCipher or DecryptionFailure.
*/
export declare const decrypt: (data: Uint8Array, key: Uint8Array, { name, iv, additionalData, tagLength }: cipherOptions, webCrypto: any) => Promise<Uint8Array>;