Example 1 — Sign a File
Write a temp file and compute its HMAC.
<?php
$file = tempnam(sys_get_temp_dir(), 'hm_');
file_put_contents($file, 'Hello, CodeToFun!');
echo hash_hmac_file('sha256', $file, 'secret-key'), PHP_EOL;
unlink($file); How It Works
- Create a temp file. It holds a known text.
- Pass the key. It must stay secret.
- Get the signature. It is 64 hex characters.
- Delete the file. Clean up after the demo.

