MCPcopy
hub / github.com/slopus/happy / decryptAESGCMString

Function decryptAESGCMString

packages/happy-app/sources/encryption/aes.web.ts:54–67  ·  view source on GitHub ↗
(data: string, key64: string)

Source from the content-addressed store, hash-verified

52}
53
54export async function decryptAESGCMString(data: string, key64: string): Promise<string | null> {
55 try {
56 const key = await importKey(key64, 'decrypt');
57 const { iv, ciphertext } = split(decodeBase64(data));
58 const plaintext = await crypto.subtle.decrypt(
59 { name: ALGO, iv: iv as BufferSource },
60 key,
61 ciphertext as BufferSource,
62 );
63 return new TextDecoder().decode(plaintext);
64 } catch {
65 return null;
66 }
67}
68
69export async function encryptAESGCM(data: Uint8Array, key64: string): Promise<Uint8Array> {
70 // Mirror aes.ts: the existing AES path round-trips bytes-as-UTF-8-strings.

Callers 2

aes.web.test.tsFile · 0.90
decryptAESGCMFunction · 0.70

Calls 4

decodeBase64Function · 0.90
importKeyFunction · 0.85
splitFunction · 0.85
decryptMethod · 0.65

Tested by

no test coverage detected