(material: SecretEncryptionMaterial)
| 66 | } |
| 67 | |
| 68 | async decrypt(material: SecretEncryptionMaterial): Promise<string> { |
| 69 | const masterKey = await this.keyPromise; |
| 70 | const iv = SecretEncryption.decode(material.iv); |
| 71 | const ciphertext = SecretEncryption.decode(material.ciphertext); |
| 72 | const authTag = material.authTag ? SecretEncryption.decode(material.authTag) : new Uint8Array(); |
| 73 | |
| 74 | const payload = new Uint8Array(ciphertext.length + authTag.length); |
| 75 | payload.set(ciphertext); |
| 76 | payload.set(authTag, ciphertext.length); |
| 77 | |
| 78 | const decrypted = await crypto.subtle.decrypt( |
| 79 | { name: 'AES-GCM', iv: SecretEncryption.toArrayBuffer(iv) }, |
| 80 | masterKey, |
| 81 | SecretEncryption.toArrayBuffer(payload) |
| 82 | ); |
| 83 | |
| 84 | return new TextDecoder().decode(decrypted); |
| 85 | } |
| 86 | |
| 87 | private async normalizeKey( |
| 88 | masterKey: CryptoKey | ArrayBuffer | ArrayBufferView, |
no test coverage detected