pub fn hmac_sha256(key: &[u8], data: &[u8]) -> Result<[u8; 32], Error>
Expand description
Computes an HMAC-SHA256 signature for the provided key and data.
This function generates an HMAC (Hash-based Message Authentication Code) using the SHA-256 hashing algorithm. The key and data are processed, and the resulting 256-bit (32-byte) signature is returned.
§Parameters
key
: A byte slice representing the secret key used for the HMAC computation.data
: A byte slice containing the data to be authenticated.
§Returns
[u8; 32]
: A 32-byte array containing the HMAC-SHA256 signature.Err(error::Error)
: An error if there is a failure during the HMAC computation (e.g., key or data issues, cryptographic errors).
§Example
use amebazii::util::hmac_sha256;
let key = b"secret";
let data = b"message";
let signature = hmac_sha256(key, data).unwrap();
assert_eq!(signature.len(), 32); // The HMAC-SHA256 signature should be 32 bytes.
§Errors
This function may return an error if any step in the HMAC-SHA256 computation fails.