#aes-gcm #aes #stream #gcm #encryption #crypto

aes-gcm-stream

AES GCM 流式加密和解密库,支持AES128/192/256位密钥

6个版本

0.2.3 2023年11月30日
0.2.2 2023年10月15日
0.2.0 2023年9月1日
0.1.1 2023年8月27日

#626加密学

Download history 62/week @ 2024-04-15 34/week @ 2024-04-22 13/week @ 2024-04-29 71/week @ 2024-05-06 87/week @ 2024-05-13 53/week @ 2024-05-20 92/week @ 2024-05-27 117/week @ 2024-06-03 60/week @ 2024-06-10 49/week @ 2024-06-17 61/week @ 2024-06-24 15/week @ 2024-07-08 9/week @ 2024-07-15 68/week @ 2024-07-22 34/week @ 2024-07-29

每月 126 次下载
用于 tiny-encrypt

MIT/Apache

44KB
891 代码行

aes-gcm-stream

Crates | 文档

加密

// IMPORTANT! key and nonce SHOULD generate by random
let mut key = [0u8; 32];
let mut nonce = [0; 12];

let mut encryptor = Aes256GcmStreamEncryptor::new(key.clone(), &nonce);

let mut ciphertext = vec![];
ciphertext.extend_from_slice(&encryptor.update(b"Hello "));
ciphertext.extend_from_slice(&encryptor.update(b" World"));
ciphertext.extend_from_slice(&encryptor.update(b"!"));
let (last_block, tag) = encryptor.finalize();
ciphertext.extend_from_slice(&last_block);
ciphertext.extend_from_slice(&tag);

println!("Ciphertext: {}", hex::encode(&ciphertext));

运行示例

打开示例: encrypt_and_decrypt.rs

$ cargo run --example encrypt_and_decrypt
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/examples/encrypt_and_decrypt`
Ciphertext: 86c22c5122404b39683ca9b79b889fd00a6212d1be2ebc3f4f8f22f90b
Plaintext: Hello  World!

基准测试 @MacBook Pro (Retina, 15英寸,2013年晚些时候/2 GHz 四核 Intel Core i7)

$ cargo run --release --example bench
AES128 encrypt         : 483.04 M/s
AES192 encrypt         : 466.22 M/s
AES256 encrypt         : 451.38 M/s
AES256 en/decrypt      : 222.66 M/s
AES256 encrypt aes-gcm : 547.63 M/s

感谢

依赖项

~1–1.4MB
~32K SLoC