(key: string, payload: string)
| 24 | } |
| 25 | |
| 26 | export 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 | |
| 46 | async function getKey(key: string) { |
| 47 | return await crypto.subtle.importKey('raw', encodeBase64(key), { name: 'AES-CBC' }, false, ['encrypt', 'decrypt']); |
nothing calls this directly
no test coverage detected