| 82 | * Decrypt data using NaCl secretbox (legacy) |
| 83 | */ |
| 84 | export function decryptLegacy(data: Uint8Array, secret: Uint8Array): any | null { |
| 85 | const nonce = data.slice(0, tweetnacl.secretbox.nonceLength); |
| 86 | const encrypted = data.slice(tweetnacl.secretbox.nonceLength); |
| 87 | const decrypted = tweetnacl.secretbox.open(encrypted, nonce, secret); |
| 88 | if (!decrypted) { |
| 89 | return null; |
| 90 | } |
| 91 | return JSON.parse(new TextDecoder().decode(decrypted)); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Encrypt data using AES-256-GCM with the data encryption key |