add hmac
This commit is contained in:
@@ -1,3 +1,15 @@
|
|||||||
fn main() {
|
use ring::{hmac, rand, error::Unspecified};
|
||||||
println!("Hello, world!");
|
|
||||||
|
fn main() -> Result<(), Unspecified> {
|
||||||
|
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");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user