Skip to content

Commit 83da516

Browse files
committed
Add key generation and base64 encoding and decoding utils.
1 parent 617c47e commit 83da516

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/utils/encryptionUtils.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,20 @@ export async function decryptAESGCM(ciphertextArray, key) {
1717

1818
return decrypted;
1919
}
20+
21+
export async function generateKey() {
22+
const algorithm = { name: "AES-GCM", length: 256 };
23+
const key = await crypto.subtle.generateKey(algorithm, true, ["encrypt", "decrypt"]);
24+
25+
return await crypto.subtle.exportKey("raw", key);
26+
}
27+
28+
export function encodeArrayToBase64(array) {
29+
const chars = String.fromCharCode.apply(null, array);
30+
return btoa(chars);
31+
}
32+
33+
export function decodeBase64ToArray(base64) {
34+
const chars = atob(base64);
35+
return new Uint8Array(chars.split("").map(c => c.charCodeAt(0)));
36+
}

0 commit comments

Comments
 (0)