To create a Blake2s hash from a string in Rust, you can use the blake2::Blake2s
struct from the blake2
crate. First, add the blake2
dependency to your Cargo.toml
file:
32 chars3 lines
Then, use the blake2::digest::Digest
trait to create a hash from your string:
main.rs304 chars11 lines
In this example, we create a new Blake2s
instance and call update
on it with the bytes of our input string. Then, we call finalize
to compute the hash value. Finally, we format the result as a hexadecimal string and print it. The output should be:
main.rs96 chars2 lines
gistlibby LogSnag