Skip to content

Commit

Permalink
Add key generation and base64 encoding and decoding utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMasterK committed Feb 9, 2023
1 parent 617c47e commit 83da516
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/utils/encryptionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@ export async function decryptAESGCM(ciphertextArray, key) {

return decrypted;
}

export async function generateKey() {
const algorithm = { name: "AES-GCM", length: 256 };
const key = await crypto.subtle.generateKey(algorithm, true, ["encrypt", "decrypt"]);

return await crypto.subtle.exportKey("raw", key);
}

export function encodeArrayToBase64(array) {
const chars = String.fromCharCode.apply(null, array);
return btoa(chars);
}

export function decodeBase64ToArray(base64) {
const chars = atob(base64);
return new Uint8Array(chars.split("").map(c => c.charCodeAt(0)));
}

0 comments on commit 83da516

Please sign in to comment.