diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5175345 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "crypto-tool" +version = "0.0.1" +authors = ["Hatter Jiang "] +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" diff --git a/README.md b/README.md index 1af458c..8197b9c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # crypto-tool -Crypto Tool \ No newline at end of file +Crypto Tool + diff --git a/src/hmac.rs b/src/hmac.rs new file mode 100644 index 0000000..b3b32f8 --- /dev/null +++ b/src/hmac.rs @@ -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() +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..0968e66 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ + +/// HMac Utils +pub mod hmac;