Files
crypto-tool/src/hmac.rs
2019-12-29 23:33:53 +08:00

24 lines
485 B
Rust

use crypto::{
mac::{
Mac,
MacResult,
},
hmac::Hmac,
sha1::Sha1,
sha2::Sha256,
};
/// Caculte HMAC_SHA1
pub fn calc_hmac_sha1(key: &[u8], message: &[u8]) -> MacResult {
let mut hmac = Hmac::new(Sha1::new(), key);
hmac.input(message);
hmac.result()
}
// Caculate HMAC_SHA256
pub fn calc_hmac_sha256(key: &[u8], message: &[u8]) -> MacResult {
let mut hmac = Hmac::new(Sha256::new(), key);
hmac.input(message);
hmac.result()
}