-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.d.ts
29 lines (25 loc) · 1017 Bytes
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
export interface SimpleEncryptor {
/**
* Encrypts an arbitrary object using the derived cryptoKey and retursn the result as text.
* The object is first serialized to JSON (via JSON.stringify) and the result is encrypted.
*/
encrypt(obj: any): string
/**
* Decrypts the encrypted cipherText and returns back the original object deserialized from JSON.
* If the cipherText cannot be decrypted (bad key, bad text, bad serialization) then it returns null.
*/
decrypt<T = any>(cipherText: string): T | null;
/**
* Returns the HMAC(text) using the derived cryptoKey
* Defaults to returning the result as hex.
*/
hmac(text: string, encoding?: string): string
}
export interface SimpleEncryptorOptions {
key: string;
hmac: boolean;
debug: boolean;
reviver?(key: any, value: any): any;
}
export function createEncryptor(opts: SimpleEncryptorOptions): SimpleEncryptor;
export function createEncryptor(key: string): SimpleEncryptor;