This shows you the differences between two versions of the page.
uphp:functions:hash_hmac [2019/08/16 09:43] admin [See Also] |
uphp:functions:hash_hmac [2021/09/13 05:57] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======hash_hmac====== | ||
- | < | ||
- | |||
- | Generate a keyed hash value using the HMAC method | ||
- | |||
- | ====Description==== | ||
- | |||
- | <well size=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | </ | ||
- | |||
- | This can be used for cryptography or just for checksum calculations. | ||
- | |||
- | |||
- | ====Parameter==== | ||
- | |||
- | < | ||
- | ^ Parameter | ||
- | | md5 | MD5 | 32 | | ||
- | | sha1 | SHA-1 | 40 | | ||
- | | sha224 | ||
- | | sha256 | ||
- | | sha384 | ||
- | | sha512 | ||
- | |||
- | < | ||
- | |||
- | < | ||
- | ====Return Values==== | ||
- | |||
- | < | ||
- | |||
- | ====Example==== | ||
- | |||
- | <code php> | ||
- | <? | ||
- | |||
- | // Get the parameters from the URL | ||
- | |||
- | $algo=$_GET[' | ||
- | $key=$_GET[' | ||
- | $data=$_GET[' | ||
- | |||
- | |||
- | // make sure parameters are passed properly | ||
- | if (!$algo) { | ||
- | print(" | ||
- | die(); | ||
- | } | ||
- | if (!$key) { | ||
- | print(" | ||
- | die(); | ||
- | } | ||
- | if (!$data) { | ||
- | print(" | ||
- | die(); | ||
- | } | ||
- | |||
- | // calculate the hash | ||
- | $res = hash_hmac($algo, | ||
- | |||
- | // output the rsults | ||
- | print($algo." | ||
- | |||
- | ?> | ||
- | |||
- | </ | ||
- | |||
- | ====See Also==== | ||
- | |||
- | [[md5()]] - Calculate the MD5 hash of a < | ||
- | |||
- | [[sha1()]] - Calculate the SHA-1 hash of a < | ||
- | |||
- | [[md5_file()]] - Calculate the MD5 hash of a file | ||
- | |||
- | [[aes_decrypt()]] - Decrypt a string using the AES algorithm | ||
- | |||
- | [[aes_encrypt()]] - Encrypt a string using the AES algorithm |