以求哈希为例子

1
2
3
4
5
6
7
8
9
[package]
name = "list"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rust-crypto = "0.2" //使用外部的包
  • src/main.rs
1
2
3
4
5
6
7
8
9
10
use crypto::digest::Digest;
use crypto::sha3::Sha3;

fn main() {
let mut hasher = Sha3::sha3_256();
hasher.input_str("Hello world");

let result = hasher.result_str(); //求出的哈希值
println!("Hello world");
}
  • 之后进行运行
1
cargo run