GeneIT/geneit_backend/src/utils/crypt_utils.rs

18 lines
437 B
Rust
Raw Normal View History

2023-08-07 12:53:44 +00:00
use sha2::{Digest, Sha256, Sha512};
2023-08-07 09:07:24 +00:00
/// Compute hash of a slice of bytes
2023-08-07 12:53:44 +00:00
pub fn sha256(bytes: &[u8]) -> String {
let mut hasher = Sha256::new();
hasher.update(bytes);
let h = hasher.finalize();
format!("{:x}", h)
}
/// Compute hash of a slice of bytes (sha512)
2023-08-07 09:07:24 +00:00
pub fn sha512(bytes: &[u8]) -> String {
let mut hasher = Sha512::new();
hasher.update(bytes);
let h = hasher.finalize();
format!("{:x}", h)
}