init commit
This commit is contained in:
16
Cargo.toml
Normal file
16
Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "crypto-tool"
|
||||
version = "0.0.1"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
readme = "README.md"
|
||||
repository = "https://git.hatter.ink/hatter/crypto-tool"
|
||||
license = "MIT"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rust-crypto = "0.2.36"
|
||||
base64 = "0.11.0"
|
||||
urlencoding = "1.0.0"
|
||||
rust_util="0.2.0"
|
||||
23
src/hmac.rs
Normal file
23
src/hmac.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
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()
|
||||
}
|
||||
3
src/lib.rs
Normal file
3
src/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
/// HMac Utils
|
||||
pub mod hmac;
|
||||
Reference in New Issue
Block a user