feat: aes_gcm_decrypt

This commit is contained in:
2023-09-07 23:20:30 +08:00
parent 17fed2d195
commit 9e269023c6
2 changed files with 14 additions and 8 deletions

View File

@@ -1,3 +1,14 @@
use aes_gcm_stream::Aes256GcmStreamDecryptor;
use rust_util::{opt_result, XResult};
pub fn aes_gcm_decrypt(key: &[u8], nonce: &[u8], message: &[u8]) -> XResult<Vec<u8>> {
let key: [u8; 32] = opt_result!(key.try_into(), "Invalid envelop: {}");
let mut aes256_gcm = Aes256GcmStreamDecryptor::new(key, nonce);
let mut b1 = aes256_gcm.update(message);
let b2 = opt_result!(aes256_gcm.finalize(), "Invalid envelop: {}");
b1.extend_from_slice(&b2);
Ok(b1)
}
#[test]
fn test_aes_gcm_01() {