The Laravel\SerializableClosure\Signers\Hmac class implements the Signer contract to provide HMAC-based integrity protection for serialized data. It uses the sha256 algorithm to generate a hash of the serialized string using a provided secret key.
When you call sign(), it returns an array containing the original serialized string and a base64-encoded hash. When you call verify(), it checks the provided signature array against the secret to ensure the data has not been tampered with.
Signature Format
The sign() method returns an associative array with the following structure:
serializable: The original serialized string.hash: A base64-encoded HMAC hash.
Verification
The verify() method expects an array with the exact same keys (serializable and hash) and returns true if the hash matches the content, or false otherwise.
use Laravel\SerializableClosure\Signers\Hmac;
$signer = new Hmac('your-secret-key');
// Signing data
$signature = $signer->sign($serializedData);
// Verifying data
if ($signer->verify($signature)) {
// Data is authentic
}