df-crypto 0.1.5

This is an crypto
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use hmac::{Hmac, Mac};
use sha2::Sha256;

type HmacSha256 = Hmac<Sha256>;

/// 字符串
pub fn str_to_hmacsha256(key: &str, input: &str) -> String {
    let mut mac = HmacSha256::new_from_slice(key.as_bytes()).expect("HMAC can take key of any size");
    mac.update(input.as_bytes());
    let result = mac.finalize();
    let code_bytes = result.into_bytes();
    let contents: String = code_bytes.iter().map(|&c| format!("{:x}",c)).collect();
    format!("{:?}", contents)
}