Module sha

Source
Expand description

Module for creating sha1, sha256 and sha512 hashes.

§Sha

Example of computing a sha1, sha256 and sha512 hashes:

use crypto_utils::sha::{Algorithm, CryptographicHash};

// Sha1
let hash: Vec<u8> = CryptographicHash::hash(Algorithm::SHA1, b"input");

// Sha256
let hash: Vec<u8> = CryptographicHash::hash(Algorithm::SHA256, b"input");

// Sha512
let hash: Vec<u8> = CryptographicHash::hash(Algorithm::SHA512, b"input");

§HMAC-Sha

Read about HMAC in wikipedia

Example of computing a HMAC hashes (sha1, sha256 and sha512):

use crypto_utils::sha::{AlgorithmMac, CryptographicMac};

// secret value
const SECRET: &[u8] = b"secret";

// HMAC Sha1
let hash: Vec<u8> = CryptographicMac::hash(AlgorithmMac::HmacSHA1, SECRET, b"input").unwrap();

// HMAC Sha256
let hash: Vec<u8> = CryptographicMac::hash(AlgorithmMac::HmacSHA256, SECRET, b"input").unwrap();

// HMAC Sha512
let hash: Vec<u8> = CryptographicMac::hash(AlgorithmMac::HmacSHA512, SECRET, b"input").unwrap();

Enums§

Algorithm
Hashing algorithms
AlgorithmMac
HMAC hashing algorithms
CryptographicHash
Compute cryptographic hash from bytes (sha1, sha256, sha512).
CryptographicMac
Compute cryptographic hash from bytes (HMAC Sha1, HMAC Sha256, HMAC Sha512).
Error
Custom error type

Type Aliases§

Result
Alias to a Resuly<T, Error> with the cutom Error.