27 lines
701 B
Rust
27 lines
701 B
Rust
use ring::{
|
|
hmac, rand, error::Unspecified,
|
|
digest,
|
|
};
|
|
|
|
fn main() -> Result<(), Unspecified> {
|
|
{
|
|
println!("{} HHmac {}", "-".repeat(10), "-".repeat(10));
|
|
let rng = rand::SystemRandom::new();
|
|
let key = hmac::Key::generate(hmac::HMAC_SHA256, &rng)?;
|
|
|
|
let msg = "hello, world";
|
|
let tag = hmac::sign(&key, msg.as_bytes());
|
|
|
|
println!("{:?}", tag);
|
|
hmac::verify(&key, msg.as_bytes(), tag.as_ref())?;
|
|
println!("Verify success");
|
|
}
|
|
{
|
|
println!("{} SHA256 {}", "-".repeat(10), "-".repeat(10));
|
|
let sha256 = digest::digest(&digest::SHA256, b"hello, world");
|
|
println!("{:?}", sha256);
|
|
}
|
|
|
|
Ok(())
|
|
}
|