6 个版本
| 0.2.0 | 2022年9月15日 |
|---|---|
| 0.1.4 | 2022年5月9日 |
| 0.1.2 | 2022年1月24日 |
| 0.1.1 | 2021年10月31日 |
#1559 in 密码学
56 次每月下载
39KB
938 行
aead-io
提供对 Write/Read 对象和 StreamPrimitive 的包装,以提供一个易于使用正确加密的接口。
let key = b"my very super super secret key!!".into();
let plaintext = b"hello world!";
let ciphertext = {
let mut ciphertext = Vec::default();
let mut writer = EncryptBE32BufWriter::<ChaCha20Poly1305, _, _>::new(
key,
&Default::default(), // please use a better nonce ;)
Vec::with_capacity(128),
&mut ciphertext,
)
.unwrap();
writer.write_all(plaintext)?;
writer.flush()?;
ciphertext
};
let decrypted = {
let mut reader = DecryptBE32BufReader::<ChaCha20Poly1305, _, _>::new(
key,
Vec::with_capacity(256),
ciphertext.as_slice(),
)
.unwrap();
let mut out = Vec::new();
let _ = reader.read_to_end(&mut out).unwrap();
out
};
assert_eq!(decrypted, plaintext);
#
no_std
此包与 no_std 环境兼容。只需禁用默认功能,并相应地实现 Buffer、CappedBuffer、ResizeBuffer、Write 和 Read。应该为 Vec<u8> 和字节切片提供一些默认实现。
许可协议:MIT OR Apache-2.0
依赖项
~325KB