[dependencies]
rust-crypto = "0.2.36"
- md5
use crypto::md5::Md5;
use crypto::digest::Digest;
fn main(){
let mut hasher = Md5::new();
let text = String::from("123456");
hasher.input_str(&text);
println!("{} => {}",text,hasher.result_str())
}
- sha1
use crypto::sha1::Sha1;
use crypto::digest::Digest;
fn main(){
let mut hasher = Sha1::new();
let text = String::from("123456");
hasher.input_str(&text);
println!("{} => {}",text,hasher.result_str())
}
- sha256
use crypto::sha2::Sha256;
use crypto::digest::Digest;
fn main(){
let mut hasher = Sha256::new();
let text = String::from("123456");
hasher.input_str(&text);
println!("{} => {}",text,hasher.result_str())
}
- sha512
Sha256替换成Sha512即可