From ce657011e8667f59ddb6be8d441c91d57c97dd42 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Fri, 15 May 2020 01:04:23 +0800 Subject: [PATCH] add ring::sha256 --- ring/src/main.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/ring/src/main.rs b/ring/src/main.rs index 02df33e..7b4d1d0 100644 --- a/ring/src/main.rs +++ b/ring/src/main.rs @@ -1,15 +1,26 @@ -use ring::{hmac, rand, error::Unspecified}; +use ring::{ + hmac, rand, error::Unspecified, + digest, +}; fn main() -> Result<(), Unspecified> { - let rng = rand::SystemRandom::new(); - let key = hmac::Key::generate(hmac::HMAC_SHA256, &rng)?; + { + 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()); + 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!("{:?}", 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(()) }