{"id":160,"date":"2023-02-18T21:25:05","date_gmt":"2023-02-18T13:25:05","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=160"},"modified":"2023-02-18T21:25:43","modified_gmt":"2023-02-18T13:25:43","slug":"php-hmac-md5-encrypt-algorithm","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/18\/php-hmac-md5-encrypt-algorithm\/","title":{"rendered":"PHP\u4e2d HMAC-MD5 \u52a0\u5bc6\u7b97\u6cd5"},"content":{"rendered":"<p>MD5\u5df2\u7ecf\u4e0d\u662f\u90a3\u4e48\u5b89\u5168\u4e86\uff0c\u91c7\u7528\u5b57\u5178\u53ef\u66b4\u529b\u7834\u89e3\uff0c\u901a\u5e38\u91c7\u7528\u52a0\u76d0\u7684MD5\u6216\u8005HMAC-MD5\u63d0\u5347\u5b89\u5168\u6027\u3002<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-php\">&lt;?php\n\n\/**\n * \u57fa\u4e8eMD5\u7684\u52a0\u5bc6\u7b97\u6cd5HMAC\n *\n * @param String $data \u9884\u52a0\u5bc6\u6570\u636e\n * @param String $key  \u5bc6\u94a5\n * @return String \n *\/\nfunction hmac_md5($data, $key) {\n    if (function_exists(&#039;hash_hmac&#039;)) {\n        return hash_hmac(&#039;md5&#039;, $data, $key);\n    }\n\n    $key = (strlen($key) &gt; 64) ? pack(&#039;H32&#039;, &#039;md5&#039;) : str_pad($key, 64, chr(0));\n    $ipad = substr($key,0, 64) ^ str_repeat(chr(0x36), 64);\n    $opad = substr($key,0, 64) ^ str_repeat(chr(0x5C), 64);\n    return md5($opad.pack(&#039;H32&#039;, md5($ipad.$data)));\n}\n\n?&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>MD5\u5df2\u7ecf\u4e0d\u662f\u90a3\u4e48\u5b89\u5168\u4e86\uff0c\u91c7\u7528\u5b57\u5178\u53ef\u66b4\u529b\u7834\u89e3\uff0c\u901a\u5e38\u91c7\u7528\u52a0\u76d0\u7684MD5\u6216\u8005HMAC-MD5\u63d0\u5347\u5b89\u5168\u6027\u3002 &lt;? [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[71],"class_list":["post-160","post","type-post","status-publish","format-standard","hentry","category-php-basic","tag-hmac-md5"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}