Expand description
The SHA family of hashes.
SHA, or Secure Hash Algorithms, are a family of cryptographic hashing algorithms published by the National Institute of Standards and Technology (NIST). Hash algorithms such as those in the SHA family are used to map data of an arbitrary size to a fixed-size string of bytes. As cryptographic hashing algorithms, these mappings have the property of being irreversible. This property makes hash algorithms like these excellent for uses such as verifying the contents of a file- if you know the hash you expect beforehand, then you can verify that the data you have is correct if it hashes to the same value.
Examples
When dealing with data that becomes available in chunks, such as while buffering data from IO, you can create a hasher that you can repeatedly update to add bytes to.
use openssl::sha;
let mut hasher = sha::Sha256::new();
hasher.update(b"Hello, ");
hasher.update(b"world");
let hash = hasher.finish();
println!("Hashed \"Hello, world\" to {}", hex::encode(hash));
On the other hand, if you already have access to all of the data you would like to hash, you may prefer to use the slightly simpler method of simply calling the hash function corresponding to the algorithm you want to use.
use openssl::sha::sha256;
let hash = sha256(b"your data or message");
println!("Hash = {}", hex::encode(hash));
Structs
- An object which calculates a SHA1 hash of some data.
- An object which calculates a SHA224 hash of some data.
- An object which calculates a SHA256 hash of some data.
- An object which calculates a SHA384 hash of some data.
- An object which calculates a SHA512 hash of some data.
Functions
- Computes the SHA1 hash of some data.
- Computes the SHA224 hash of some data.
- Computes the SHA256 hash of some data.
- Computes the SHA384 hash of some data.
- Computes the SHA512 hash of some data.