{"id":47,"date":"2023-06-05T13:02:27","date_gmt":"2023-06-05T05:02:27","guid":{"rendered":"http:\/\/pro369.com\/php\/?p=47"},"modified":"2019-04-29T00:45:04","modified_gmt":"2019-04-29T00:45:04","slug":"php%e4%bd%bf%e7%94%a8mcrypt%e6%8b%93%e5%b1%95%e7%9a%84%e5%8a%a0%e5%af%86%e7%ae%97%e6%b3%95%e9%80%b2%e8%a1%8c%e5%8a%a0%e5%af%86%e8%a7%a3%e5%af%86","status":"publish","type":"post","link":"https:\/\/por.tw\/php\/php%e4%bd%bf%e7%94%a8mcrypt%e6%8b%93%e5%b1%95%e7%9a%84%e5%8a%a0%e5%af%86%e7%ae%97%e6%b3%95%e9%80%b2%e8%a1%8c%e5%8a%a0%e5%af%86%e8%a7%a3%e5%af%86\/","title":{"rendered":"PHP\u4f7f\u7528mcrypt\u62d3\u5c55\u7684\u52a0\u5bc6\u7b97\u6cd5\u9032\u884c\u52a0\u5bc6\u89e3\u5bc6"},"content":{"rendered":"<p><strong><font color=\"#008000\">\u8cc7\u6599\u52a0\u5bc6\u5728\u6211\u5011\u751f\u6d3b\u4e2d\u7684\u5730\u4f4d\u5df2\u7d93\u8d8a\u4f86\u8d8a\u91cd\u8981\u4e86\uff0c\u5c24\u5176\u662f\u8003\u616e\u5230\u5728\u7db2\u8def\u4e0a\u767c\u751f\u7684\u5927\u91cf\u4ea4\u6613\u548c\u50b3\u8f38\u7684\u5927\u91cf\u8cc7\u6599\u3002<\/font><br \/> \u5c0d\u65bc\u4e0d\u9700\u8981\u5fa9\u539f\u70ba\u539f\u59cb\u8cc7\u6599\u7684\u8a0a\u606f\u6211\u5011\u53ef\u4ee5\u4f7f\u7528MD5\u3001sha1\u7b49\u4e0d\u53ef\u9006\u52a0\u5bc6\u7b97\u6cd5\u5c0d\u8cc7\u6599\u9032\u884c\u52a0\u5bc6\u8655\u7406\uff0c\u4f46\u5c0d\u65bc\u4ea4\u6613\u8a0a\u606f\u7b49\u9700\u8981\u5fa9<font color=\"#0000FF\">\u539f\u70ba\u539f\u59cb\u8cc7\u6599\u7684\u91cd\u8981\u8a0a\u606f\u5247\u5fc5\u9808\u4f7f\u7528\u53ef\u5fa9\u539f\u7684\u52a0\u5bc6\u7b97\u6cd5\u9032\u884c\u52a0\u5bc6\u4e86\u3002<\/font><br \/> \u7576\u7136\u4f60\u53ef\u4ee5\u81ea\u5df1\u5beb\u4e00\u500b\u53ef\u9006\u52a0\u5bc6\u7684\u7b97\u6cd5\u9032\u884c\u52a0\u5bc6\u548c\u89e3\u5bc6\u8a08\u7b97\u3002<br \/> <font color=\"#800080\">\u672c\u6587\u4e2d\u6211\u5011\u4ecb\u7d39\u7684\u662f\u4f7f\u7528 mcrypt\u6a21\u7d44\u9032\u884c\u52a0\u5bc6\u89e3\u5bc6\u64cd\u4f5c\u3002<\/font><\/strong><\/p>\n<p> <font color=\"#800000\"><strong>Mcrypt\u7684\u512a\u9ede\u4e0d\u50c5\u50c5\u5728\u65bc\u5176\u63d0\u4f9b\u7684\u52a0\u5bc6\u7b97\u6cd5\u8f03\u591a\uff0c\u5728windows\u4e0b\u96a8PHP\u5305\u4e00\u8d77\u767c\u4f48\uff0c\u9084\u5728\u65bc\u5b83\u53ef\u4ee5\u5c0d\u8cc7\u6599\u9032\u884c\u52a0\/\u89e3\u5bc6\u8655\u7406\uff0c\u6b64\u5916\uff0c\u5b83\u9084\u63d0\u4f9b\u4e86\u5167\u542bDES\u7b97\u6cd5\u5728\u5167\u768435\u7a2e\u8655\u7406\u8cc7\u6599\u7528\u7684\u51fd\u6578\u3002<\/strong><\/font><br \/> \/**<br \/> &nbsp;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/> &nbsp;* Mcrypt \u52a0\u5bc6\/\u89e3\u5bc6<br \/> &nbsp;* @param String $date \u8981\u52a0\u5bc6\u548c\u89e3\u5bc6\u7684\u8cc7\u6599<br \/> &nbsp;* @param String $mode encode \u9810\u8a2d\u70ba\u52a0\u5bc6\/decode \u70ba\u89e3\u5bc6<br \/> &nbsp;* @return String<br \/> &nbsp;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/> &nbsp;* @example<br \/> &nbsp;*\/<br \/> function ZxingCrypt($date,$mode = &#39;encode&#39;){<br \/> &nbsp;&nbsp;&nbsp; $key = md5(&#39;zxing&#39;);\/\/\u7528MD5\u54c8\u5e0c\u751f\u6210\u4e00\u500b\u5bc6\u9470\uff0c\u6ce8\u610f\u52a0\u5bc6\u548c\u89e3\u5bc6\u7684\u5bc6\u9470\u5fc5\u9808\u7d71\u4e00<br \/> &nbsp;&nbsp;&nbsp; if ($mode == &#39;decode&#39;){<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $date = base64_decode($date);<br \/> &nbsp;&nbsp;&nbsp; }<br \/> &nbsp;&nbsp;&nbsp; if (function_exists(&#39;mcrypt_create_iv&#39;)){<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);<br \/> &nbsp;&nbsp;&nbsp; }<br \/> &nbsp;&nbsp;&nbsp; if (isset($iv) &amp;&amp; $mode == &#39;encode&#39;){<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $date, MCRYPT_MODE_ECB, $iv);<br \/> &nbsp;&nbsp;&nbsp; }elseif (isset($iv) &amp;&amp; $mode == &#39;decode&#39;){<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $passcrypt = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $date, MCRYPT_MODE_ECB, $iv);<br \/> &nbsp;&nbsp;&nbsp; }<br \/> &nbsp;&nbsp;&nbsp; if ($mode == &#39;encode&#39;){<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $passcrypt = base64_encode($passcrypt);<br \/> &nbsp;&nbsp;&nbsp; }<br \/> &nbsp;&nbsp;&nbsp; return $passcrypt;<br \/> }<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8cc7\u6599\u52a0\u5bc6\u5728\u6211\u5011\u751f\u6d3b\u4e2d\u7684\u5730\u4f4d\u5df2\u7d93\u8d8a\u4f86\u8d8a\u91cd\u8981\u4e86\uff0c\u5c24\u5176\u662f\u8003\u616e\u5230\u5728\u7db2\u8def\u4e0a\u767c\u751f\u7684\u5927\u91cf\u4ea4\u6613\u548c\u50b3\u8f38\u7684\u5927\u91cf\u8cc7\u6599\u3002 \u5c0d\u65bc\u4e0d\u9700\u8981\u5fa9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":391,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[22],"class_list":["post-47","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-php"],"_links":{"self":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts\/47"}],"collection":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":0,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/media\/391"}],"wp:attachment":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}