Key for HMAC Algorithm [closed]
How to generate the secret key for the HMAC algorithm as I have to use it for data verification at the other cl开发者_如何学Goients end?
Thanks in advance.
The HMAC key must be pre-shared between the server and the client (both must known the key before you exchange messages).
You can generate the key in any way you want, for example by reading some bytes from /dev/random:
$fd = fopen('/dev/random', 'r');
$bytes = fread($fd, '64);
Then you can calculate the HMAC using hash_hmac
:
$hash = hash_hmac('sha1', $data, $key);
精彩评论