MCPcopy Create free account
hub / github.com/stackblitz/bolt.new / decrypt

Function decrypt

app/lib/crypto.ts:26–44  ·  view source on GitHub ↗
(key: string, payload: string)

Source from the content-addressed store, hash-verified

24}
25
26export async function decrypt(key: string, payload: string) {
27 const bundle = encodeBase64(payload);
28
29 const iv = new Uint8Array(bundle.buffer, bundle.byteLength - IV_LENGTH);
30 const ciphertext = new Uint8Array(bundle.buffer, 0, bundle.byteLength - IV_LENGTH);
31
32 const cryptoKey = await getKey(key);
33
34 const plaintext = await crypto.subtle.decrypt(
35 {
36 name: 'AES-CBC',
37 iv,
38 },
39 cryptoKey,
40 ciphertext,
41 );
42
43 return decoder.decode(plaintext);
44}
45
46async function getKey(key: string) {
47 return await crypto.subtle.importKey('raw', encodeBase64(key), { name: 'AES-CBC' }, false, ['encrypt', 'decrypt']);

Callers

nothing calls this directly

Calls 2

encodeBase64Function · 0.85
getKeyFunction · 0.85

Tested by

no test coverage detected