@@ -30,12 +30,17 @@ export interface IEncryptedPayload {
30
30
}
31
31
32
32
/**
33
- * encrypt a string
33
+ * Encrypt a string using AES-CTR.
34
34
*
35
35
* @param data - the plaintext to encrypt
36
- * @param key - the encryption key to use
37
- * @param name - the name of the secret
38
- * @param ivStr - the initialization vector to use
36
+ * @param key - the encryption key to use as an input to the HKDF function which is used to derive the AES key for
37
+ * encryption. Obviously, the same key must be provided when decrypting.
38
+ * @param name - the name of the secret. Used as an input to the HKDF operation which is used to derive the AES key,
39
+ * so again the same value must be provided when decrypting.
40
+ * @param ivStr - the base64-encoded initialization vector to use. If not supplied, a random one will be generated.
41
+ *
42
+ * @returns The encrypted result, including the ciphertext itself, the initialization vector (as supplied in `ivStr`,
43
+ * or generated), and an HMAC on the ciphertext — all base64-encoded.
39
44
*/
40
45
export async function encryptAES (
41
46
data : string ,
@@ -79,11 +84,13 @@ export async function encryptAES(
79
84
}
80
85
81
86
/**
82
- * decrypt a string
87
+ * Decrypt an AES-encrypted string.
83
88
*
84
- * @param data - the encrypted data
85
- * @param key - the encryption key to use
86
- * @param name - the name of the secret
89
+ * @param data - the encrypted data, returned by {@link encryptAES}.
90
+ * @param key - the encryption key to use as an input to the HKDF function which is used to derive the AES key. Must
91
+ * be the same as provided to {@link encryptAES}.
92
+ * @param name - the name of the secret. Also used as an input to the HKDF operation which is used to derive the AES
93
+ * key, so again must be the same as provided to {@link encryptAES}.
87
94
*/
88
95
export async function decryptAES ( data : IEncryptedPayload , key : Uint8Array , name : string ) : Promise < string > {
89
96
const [ aesKey , hmacKey ] = await deriveKeys ( key , name ) ;
0 commit comments