@bicycle-codes/simple-aes
Version:
An easy way to use symmetric keys in browsers or node
51 lines • 1.68 kB
TypeScript
import type { Msg } from './types.js';
import { SymmAlg } from './types.js';
export type { Message } from './types.js';
export declare enum SymmKeyLength {
B128 = 128,
B192 = 192,
B256 = 256
}
export declare const DEFAULT_SYMM_LEN = SymmKeyLength.B256;
/**
* Take a message object, create a new AES key, and encrypt the message with the
* key. Return encrypted message and the key, encoded as `base64url`.
*
* @param msg The message to encrypt.
* @returns {Promise<[
* { content:string },
* { key:string }
* ]>} The encrypted message and key.
*/
export declare function encryptMessage(msg: {
content: string;
}, opts?: {
length: SymmKeyLength;
}): Promise<[{
content: string;
}, {
key: string;
}]>;
export declare function aesEncrypt(_data: Uint8Array | string, cryptoKey: CryptoKey, alg: SymmAlg, iv?: Uint8Array): Promise<Uint8Array>;
type SymmKeyOpts = {
alg: SymmAlg;
length: SymmKeyLength;
iv: ArrayBuffer;
};
type CipherText = ArrayBuffer;
export declare function encryptBytes(msg: Msg, key: CryptoKey | string, opts?: Partial<SymmKeyOpts>): Promise<CipherText>;
/**
* Take a message and a `base64url` encoded string as a key.
* Return the decrypted message object.
*
* @param msg The message object
* @param keyString The `base64url` encoded key
* @returns {Promise<{ content:string }>} The decrypted message object.
*/
export declare function decryptMessage(msg: {
content: string;
}, keyString: string): Promise<{
content: string;
}>;
export declare function aesDecrypt(encrypted: Uint8Array, cryptoKey: CryptoKey, alg: SymmAlg, iv?: Uint8Array): Promise<Uint8Array>;
//# sourceMappingURL=index.d.ts.map