MCPcopy Create free account
hub / github.com/backnotprop/plannotator / decrypt

Function decrypt

packages/shared/crypto.ts:52–77  ·  view source on GitHub ↗
(
  ciphertext: string,
  key: string
)

Source from the content-addressed store, hash-verified

50 * Returns the original compressed base64url string.
51 */
52export async function decrypt(
53 ciphertext: string,
54 key: string
55): Promise<string> {
56 const combined = base64urlToBytes(ciphertext);
57 const rawKey = base64urlToBytes(key);
58
59 const iv = combined.slice(0, 12);
60 const encrypted = combined.slice(12);
61
62 const cryptoKey = await crypto.subtle.importKey(
63 'raw',
64 rawKey.buffer as ArrayBuffer,
65 { name: 'AES-GCM', length: 256 },
66 false,
67 ['decrypt']
68 );
69
70 const decrypted = await crypto.subtle.decrypt(
71 { name: 'AES-GCM', iv },
72 cryptoKey,
73 encrypted
74 );
75
76 return new TextDecoder().decode(decrypted);
77}
78
79// --- Helpers ---
80

Callers 2

crypto.test.tsFile · 0.90
loadFromPasteIdFunction · 0.90

Calls 1

base64urlToBytesFunction · 0.85

Tested by

no test coverage detected