feat: add hmac_sha1

This commit is contained in:
2022-04-03 22:30:16 +08:00
parent 46d24a8e24
commit 72a8969453
3 changed files with 149 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
use hmac::{Hmac, Mac};
use sha1::Sha1;
const SHA1_DIGEST_SIZE: usize = 20;
type HmacSha1 = Hmac<Sha1>;
fn main() {
let args = std::env::args().into_iter().collect::<Vec<String>>();
println!("Args: {:?}", args);
let key = hex::decode(&args[1]).expect("Key hex parse failed");
let data = hex::decode(&args[2]).expect("Data hex parse failed");
let mut hmac_sha1 = HmacSha1::new_from_slice(&key).unwrap();
hmac_sha1.update(&data);
let result = hmac_sha1.finalize();
let mut code = [0; SHA1_DIGEST_SIZE];
code.copy_from_slice(result.into_bytes().as_slice());
println!("{}", hex::encode(&code));
}