Skip to content

Commit 60cedf2

Browse files
authored
Improve documentation on {encrypt,decrypt}AES (#4397)
1 parent ed44514 commit 60cedf2

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/crypto/aes.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ export interface IEncryptedPayload {
3030
}
3131

3232
/**
33-
* encrypt a string
33+
* Encrypt a string using AES-CTR.
3434
*
3535
* @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.
3944
*/
4045
export async function encryptAES(
4146
data: string,
@@ -79,11 +84,13 @@ export async function encryptAES(
7984
}
8085

8186
/**
82-
* decrypt a string
87+
* Decrypt an AES-encrypted string.
8388
*
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}.
8794
*/
8895
export async function decryptAES(data: IEncryptedPayload, key: Uint8Array, name: string): Promise<string> {
8996
const [aesKey, hmacKey] = await deriveKeys(key, name);

0 commit comments

Comments
 (0)