Turn: HmacMD5 algorithm [php] PHP code
Function HmacMd5 ($ data, $ key) {// RFC 2104 HMAC implementation for php. // Creates an md5 HMAC. // Eliminates the need to install mhash to compute a HMAC // Hacked by Lance Rushing (NOTE: Hacked means written) // you need to configure the environment to support iconv, otherwise the Chinese parameter cannot be properly processed $ key = iconv ("GB2312", "UTF-8", $ key); $ data = iconv ("GB2312", "UTF-8", $ data ); $ B = 64; // byte length for md5 if (strlen ($ key)> $ B) {$ key = pack ("H *", md5 ($ key) ;}$ key = str_pad ($ key, $ B, chr (0x00); $ ipad = str_pad ('', $ B, chr (0x36); $ opad = str_pad ('', $ B, chr (0x5c); $ k_ipad = $ key ^ $ ipad; $ k_opad = $ key ^ $ opad; return md5 ($ k_opad. pack ("H *", md5 ($ k_ipad. $ data )));}
HMAC requires an encryption hash function (represented as H) and a key K.
Assume that H is a hash function that encrypts data blocks with a basic iterative compression function.
B indicates the length of the data block. (The split data block length of the hash function mentioned above is B = 64). use L to indicate the output data length of the hash function (L = 16, SHA? 1 in L = 20 ).
The key length can be any positive integer smaller than or equal to the length of the data block. If the key length used in the application is larger than that of B, hash is used first.
Function H acts on it, and then uses the L-length string output by H as the actual key used in HMAC.
Generally, the recommended minimum key K length is L. (The length of the output data is equal to that of H ).