File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -83,15 +83,21 @@ function decryptWithKey(
8383 const plainText = Buffer . allocUnsafeSlow (
8484 macAndCipherText . byteLength - macSize ,
8585 ) ;
86- // This returns the number of bytes that has been decrypted
87- const decrypted = sodium . crypto_aead_xchacha20poly1305_ietf_decrypt (
88- plainText ,
89- null ,
90- macAndCipherText ,
91- additionalData ,
92- nonce ,
93- key ,
94- ) ;
86+ let decrypted : number ;
87+ try {
88+ // This returns the number of bytes that has been decrypted
89+ // It will throw if the MAC cannot be authenticated
90+ decrypted = sodium . crypto_aead_xchacha20poly1305_ietf_decrypt (
91+ plainText ,
92+ null ,
93+ macAndCipherText ,
94+ additionalData ,
95+ nonce ,
96+ key ,
97+ ) ;
98+ } catch {
99+ return ;
100+ }
95101 if ( decrypted !== plainText . byteLength ) {
96102 return ;
97103 }
You can’t perform that action at this time.
0 commit comments