3个版本 (破坏性)
0.3.1 | 2023年6月17日 |
---|---|
0.3.0 |
|
0.2.0 | 2023年6月15日 |
0.1.0 | 2023年5月25日 |
#1898 在 密码学
每月 22 次下载
25KB
421 代码行
TableSalt
描述
TableSalt是libsodium的安全、氧化包装器。
用法
要使用tablesalt,首先在您的Cargo.toml
文件中将它添加为依赖项。
[dependencies]
tablesalt = "0.3.1"
哈希
目前,TableSalt仅提供libsodium的crypto_generichash API。
哈希消息
以下示例展示了如何哈希一个简单的消息。这里的代码使用crate hex
将哈希编码为一个十六进制字符串,这是一个Vec<u8>
。
use tablesalt::sodium;
fn main() {
let s = sodium::Sodium::new();
let hash = s.crypto_generichash(b"Some message", None, 32);
println!("blake2b hash: {}", hex::encode(&hash));
}
哈希多部分消息
use tablesalt::sodium;
fn main() {
let s = sodium::Sodium::new();
let mut state = s.crypto_generichash_init(None, 32);
state.update(b"Some ");
state.update(b"message");
let hash = state.finalize();
println!("blake2b hash: {}", hex::encode(&hash));
}
依赖
~15MB
~67K SLoC