MCPcopy Create free account
hub / github.com/dailydotdev/apps / decrypt

Function decrypt

packages/shared/src/components/crypto.ts:6–31  ·  view source on GitHub ↗
(
  input: string,
  key: string,
  algorithmName = 'AES-CBC',
  algorithmLength = 256,
  subtle = globalThis.crypto.subtle,
)

Source from the content-addressed store, hash-verified

4 Uint8Array.from(atob(b), (c) => c.charCodeAt(0));
5
6export const decrypt = async (
7 input: string,
8 key: string,
9 algorithmName = 'AES-CBC',
10 algorithmLength = 256,
11 subtle = globalThis.crypto.subtle,
12): Promise<string> => {
13 if (!subtle || (isDevelopment && !isProductionAPI)) {
14 return input;
15 }
16 const keyObject = await subtle.importKey(
17 'raw',
18 new TextEncoder().encode(key),
19 { name: algorithmName, length: algorithmLength },
20 true,
21 ['encrypt', 'decrypt'],
22 );
23 const [iv, cipherText] = input.split(':');
24 const plainTextBuffer = await subtle.decrypt(
25 { name: algorithmName, iv: base64ToBuf(iv) },
26 keyObject,
27 base64ToBuf(cipherText),
28 );
29
30 return new TextDecoder().decode(plainTextBuffer);
31};

Callers 1

enrichBootWithFeaturesFunction · 0.90

Calls 1

base64ToBufFunction · 0.85

Tested by

no test coverage detected