I'm trying to use the SHA256 hash function provided by sodiumoxide to write a hash_string
function. This function should accept a string and return the hash of the string represented as a string.
Here's what I have so far:
extern crate sodiumoxide;
use std::string::String;
use sodiumoxide::crypto::hash::sha256;
pub fn hash_string(s: String) -> String {
let digest = sha256::hash(&s.into_bytes());
String::from_utf8_unchecked(digest).to_owned()
}
Clearly this isn't correct but I don't know how to fix it.
I was able to implement this with the rust-crypto crate.
pub fn hash_string(input: String) -> String {
let mut sha = Sha256::new();
sha.input_str(&input);
sha.result_str()
}
I want to do exactly the above but using the sodiumoxide crate instead.