{"id":307,"date":"2017-12-21T10:27:53","date_gmt":"2017-12-21T02:27:53","guid":{"rendered":"http:\/\/fengyuwuzu.cn\/?p=307"},"modified":"2017-12-21T10:27:53","modified_gmt":"2017-12-21T02:27:53","slug":"php%e4%bd%bf%e7%94%a83des%e7%ae%97%e6%b3%95%e5%8a%a0%e5%af%86%e8%a7%a3%e5%af%86%e5%ad%97%e7%ac%a6%e4%b8%b2","status":"publish","type":"post","link":"https:\/\/fengyuwuzu.cn\/?p=307","title":{"rendered":"PHP\u4f7f\u75283DES\u7b97\u6cd5\u52a0\u5bc6\u89e3\u5bc6\u5b57\u7b26\u4e32"},"content":{"rendered":"<p>3DES\uff08\u6216\u79f0\u4e3aTriple DES\uff09\u662f\u4e09\u91cd\u6570\u636e\u52a0\u5bc6\u7b97\u6cd5\uff08TDEA\uff0cTriple Data Encryption Algorithm\uff09\u5757\u5bc6\u7801\u7684\u901a\u79f0\u3002\u5b83\u76f8\u5f53\u4e8e\u662f\u5bf9\u6bcf\u4e2a\u6570\u636e\u5757\u5e94\u7528\u4e09\u6b21DES\u52a0\u5bc6\u7b97\u6cd5\u3002\u7531\u4e8e\u8ba1\u7b97\u673a\u8fd0\u7b97\u80fd\u529b\u7684\u589e\u5f3a\uff0c\u539f\u7248DES\u5bc6\u7801\u7684\u5bc6\u94a5\u957f\u5ea6\u53d8\u5f97\u5bb9\u6613\u88ab\u66b4\u529b\u7834\u89e3\uff1b3DES\u5373\u662f\u8bbe\u8ba1\u7528\u6765\u63d0\u4f9b\u4e00\u79cd\u76f8\u5bf9\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u5373\u901a\u8fc7\u589e\u52a0DES\u7684\u5bc6\u94a5\u957f\u5ea6\u6765\u907f\u514d\u7c7b\u4f3c\u7684\u653b\u51fb\uff0c\u800c\u4e0d\u662f\u8bbe\u8ba1\u4e00\u79cd\u5168\u65b0\u7684\u5757\u5bc6\u7801\u7b97\u6cd5\u3002<\/p>\n<div>3DES\uff08\u5373Triple DES\uff09\u662fDES\u5411AES\u8fc7\u6e21\u7684\u52a0\u5bc6\u7b97\u6cd5\uff081999\u5e74\uff0cNIST\u5c063-DES\u6307\u5b9a\u4e3a\u8fc7\u6e21\u7684\u52a0\u5bc6\u6807\u51c6\uff09\uff0c\u52a0\u5bc6\u7b97\u6cd5\uff0c\u5176\u5177\u4f53\u5b9e\u73b0\u5982\u4e0b\uff1a\u8bbeEk()\u548cDk()\u4ee3\u8868DES\u7b97\u6cd5\u7684\u52a0\u5bc6\u548c\u89e3\u5bc6\u8fc7\u7a0b\uff0cK\u4ee3\u8868DES\u7b97\u6cd5\u4f7f\u7528\u7684\u5bc6\u94a5\uff0cM\u4ee3\u8868\u660e\u6587\uff0cC\u4ee3\u8868\u5bc6\u6587\uff0c\u8fd9\u6837\uff1a<\/div>\n<div><\/div>\n<div>3DES\u52a0\u5bc6\u8fc7\u7a0b\u4e3a\uff1aC=Ek3(Dk2(Ek1(M)))<\/div>\n<div>3DES\u89e3\u5bc6\u8fc7\u7a0b\u4e3a\uff1aM=Dk1(EK2(Dk3(C)))<\/div>\n<div><\/div>\n<div><\/div>\n<div>\u6d41\u7a0b\u56fe\uff1a<\/div>\n<div><a href=\"http:\/\/fengyuwuzu.cn\/wp-content\/uploads\/2017\/12\/20160721195751744.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-308\" src=\"http:\/\/fengyuwuzu.cn\/wp-content\/uploads\/2017\/12\/20160721195751744-300x102.png\" alt=\"\" width=\"300\" height=\"102\" srcset=\"https:\/\/fengyuwuzu.cn\/wp-content\/uploads\/2017\/12\/20160721195751744-300x102.png 300w, https:\/\/fengyuwuzu.cn\/wp-content\/uploads\/2017\/12\/20160721195751744.png 728w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/div>\n<div>\u8981\u4f7f\u7528\u4ee5\u4e0a\u7684\u51fd\u6570\uff0c\u5728\u7f16\u8bd1PHP\u7684\u65f6\u5019\u5fc5\u987b\u6dfb\u52a0--with-mcrypt\u9009\u9879\u3002<\/div>\n<div><\/div>\n<div>PHP\u5b9e\u73b03DES\u4ee3\u7801\uff1a<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<style type=\"text\/css\">\ntd.linenos { background-color: #f0f0f0; padding-right: 10px; }<br \/>\nspan.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }<br \/>\npre { line-height: 125%; }<br \/>\nbody .hll { background-color: #ffffcc }<br \/>\nbody  { background: #f8f8f8; }<br \/>\nbody .c { color: #408080; font-style: italic } \/* Comment *\/<br \/>\nbody .err { border: 1px solid #FF0000 } \/* Error *\/<br \/>\nbody .k { color: #008000; font-weight: bold } \/* Keyword *\/<br \/>\nbody .o { color: #666666 } \/* Operator *\/<br \/>\nbody .ch { color: #408080; font-style: italic } \/* Comment.Hashbang *\/<br \/>\nbody .cm { color: #408080; font-style: italic } \/* Comment.Multiline *\/<br \/>\nbody .cp { color: #BC7A00 } \/* Comment.Preproc *\/<br \/>\nbody .c1 { color: #408080; font-style: italic } \/* Comment.Single *\/<br \/>\nbody .cs { color: #408080; font-style: italic } \/* Comment.Special *\/<br \/>\nbody .gd { color: #A00000 } \/* Generic.Deleted *\/<br \/>\nbody .ge { font-style: italic } \/* Generic.Emph *\/<br \/>\nbody .gr { color: #FF0000 } \/* Generic.Error *\/<br \/>\nbody .gh { color: #000080; font-weight: bold } \/* Generic.Heading *\/<br \/>\nbody .gi { color: #00A000 } \/* Generic.Inserted *\/<br \/>\nbody .go { color: #888888 } \/* Generic.Output *\/<br \/>\nbody .gp { color: #000080; font-weight: bold } \/* Generic.Prompt *\/<br \/>\nbody .gs { font-weight: bold } \/* Generic.Strong *\/<br \/>\nbody .gu { color: #800080; font-weight: bold } \/* Generic.Subheading *\/<br \/>\nbody .gt { color: #0044DD } \/* Generic.Traceback *\/<br \/>\nbody .kc { color: #008000; font-weight: bold } \/* Keyword.Constant *\/<br \/>\nbody .kd { color: #008000; font-weight: bold } \/* Keyword.Declaration *\/<br \/>\nbody .kn { color: #008000; font-weight: bold } \/* Keyword.Namespace *\/<br \/>\nbody .kp { color: #008000 } \/* Keyword.Pseudo *\/<br \/>\nbody .kr { color: #008000; font-weight: bold } \/* Keyword.Reserved *\/<br \/>\nbody .kt { color: #B00040 } \/* Keyword.Type *\/<br \/>\nbody .m { color: #666666 } \/* Literal.Number *\/<br \/>\nbody .s { color: #BA2121 } \/* Literal.String *\/<br \/>\nbody .na { color: #7D9029 } \/* Name.Attribute *\/<br \/>\nbody .nb { color: #008000 } \/* Name.Builtin *\/<br \/>\nbody .nc { color: #0000FF; font-weight: bold } \/* Name.Class *\/<br \/>\nbody .no { color: #880000 } \/* Name.Constant *\/<br \/>\nbody .nd { color: #AA22FF } \/* Name.Decorator *\/<br \/>\nbody .ni { color: #999999; font-weight: bold } \/* Name.Entity *\/<br \/>\nbody .ne { color: #D2413A; font-weight: bold } \/* Name.Exception *\/<br \/>\nbody .nf { color: #0000FF } \/* Name.Function *\/<br \/>\nbody .nl { color: #A0A000 } \/* Name.Label *\/<br \/>\nbody .nn { color: #0000FF; font-weight: bold } \/* Name.Namespace *\/<br \/>\nbody .nt { color: #008000; font-weight: bold } \/* Name.Tag *\/<br \/>\nbody .nv { color: #19177C } \/* Name.Variable *\/<br \/>\nbody .ow { color: #AA22FF; font-weight: bold } \/* Operator.Word *\/<br \/>\nbody .w { color: #bbbbbb } \/* Text.Whitespace *\/<br \/>\nbody .mb { color: #666666 } \/* Literal.Number.Bin *\/<br \/>\nbody .mf { color: #666666 } \/* Literal.Number.Float *\/<br \/>\nbody .mh { color: #666666 } \/* Literal.Number.Hex *\/<br \/>\nbody .mi { color: #666666 } \/* Literal.Number.Integer *\/<br \/>\nbody .mo { color: #666666 } \/* Literal.Number.Oct *\/<br \/>\nbody .sb { color: #BA2121 } \/* Literal.String.Backtick *\/<br \/>\nbody .sc { color: #BA2121 } \/* Literal.String.Char *\/<br \/>\nbody .sd { color: #BA2121; font-style: italic } \/* Literal.String.Doc *\/<br \/>\nbody .s2 { color: #BA2121 } \/* Literal.String.Double *\/<br \/>\nbody .se { color: #BB6622; font-weight: bold } \/* Literal.String.Escape *\/<br \/>\nbody .sh { color: #BA2121 } \/* Literal.String.Heredoc *\/<br \/>\nbody .si { color: #BB6688; font-weight: bold } \/* Literal.String.Interpol *\/<br \/>\nbody .sx { color: #008000 } \/* Literal.String.Other *\/<br \/>\nbody .sr { color: #BB6688 } \/* Literal.String.Regex *\/<br \/>\nbody .s1 { color: #BA2121 } \/* Literal.String.Single *\/<br \/>\nbody .ss { color: #19177C } \/* Literal.String.Symbol *\/<br \/>\nbody .bp { color: #008000 } \/* Name.Builtin.Pseudo *\/<br \/>\nbody .vc { color: #19177C } \/* Name.Variable.Class *\/<br \/>\nbody .vg { color: #19177C } \/* Name.Variable.Global *\/<br \/>\nbody .vi { color: #19177C } \/* Name.Variable.Instance *\/<br \/>\nbody .il { color: #666666 } \/* Literal.Number.Integer.Long *\/<\/p>\n<\/style>\n<p>&nbsp;<\/p>\n<h2><\/h2>\n<div class=\"highlight\" style=\"background: #f8f8f8;\">\n<pre style=\"line-height: 125%;\"><span style=\"color: #666666;\">&lt;?<\/span>php  \r\n<span style=\"color: #ba2121; font-style: italic;\">\/**<\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\"> * @author  fengyuwuzu.cn<\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\"> * @date    2017-11-30<\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\"> * @description  3DES\u52a0\u89e3\u5bc6\u7c7b<\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\"> *\/<\/span>\r\n<span style=\"color: #008000; font-weight: bold;\">class<\/span> <span style=\"color: #0000ff; font-weight: bold;\">Encrypt<\/span>  \r\n{  \r\n    <span style=\"color: #408080; font-style: italic;\">\/\/\u52a0\u5bc6\u79d8\u94a5\uff0c  <\/span>\r\n    <span style=\"color: #008000; font-weight: bold;\">private<\/span> <span style=\"color: #19177c;\">$_key<\/span>;  \r\n    <span style=\"color: #008000; font-weight: bold;\">private<\/span> <span style=\"color: #19177c;\">$_iv<\/span>;  \r\n    <span style=\"color: #008000; font-weight: bold;\">public<\/span> <span style=\"color: #008000; font-weight: bold;\">function<\/span> <span style=\"color: #0000ff;\">__construct<\/span>(<span style=\"color: #19177c;\">$key<\/span>, <span style=\"color: #19177c;\">$iv<\/span>)  \r\n    {  \r\n        <span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">_key<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #19177c;\">$key<\/span>;  \r\n        <span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">_iv<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #19177c;\">$iv<\/span>;  \r\n    }  \r\n      \r\n    <span style=\"color: #ba2121; font-style: italic;\">\/** <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * \u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c3DES\u52a0\u5bc6 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @param string \u8981\u52a0\u5bc6\u7684\u5b57\u7b26\u4e32 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @return mixed \u52a0\u5bc6\u6210\u529f\u8fd4\u56de\u52a0\u5bc6\u540e\u7684\u5b57\u7b26\u4e32\uff0c\u5426\u5219\u8fd4\u56defalse <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    *\/<\/span>  \r\n    <span style=\"color: #008000; font-weight: bold;\">public<\/span> <span style=\"color: #008000; font-weight: bold;\">function<\/span> <span style=\"color: #0000ff;\">encrypt3DES<\/span>(<span style=\"color: #19177c;\">$str<\/span>)  \r\n    {  \r\n        <span style=\"color: #19177c;\">$td<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #008000;\">mcrypt_module_open<\/span>(MCRYPT_3DES, <span style=\"color: #ba2121;\">\"\"<\/span>, MCRYPT_MODE_CBC, <span style=\"color: #ba2121;\">\"\"<\/span>);  \r\n        <span style=\"color: #008000; font-weight: bold;\">if<\/span> (<span style=\"color: #19177c;\">$td<\/span> <span style=\"color: #666666;\">===<\/span> <span style=\"color: #008000; font-weight: bold;\">false<\/span>) {  \r\n            <span style=\"color: #008000; font-weight: bold;\">return<\/span> <span style=\"color: #008000; font-weight: bold;\">false<\/span>;  \r\n        }  \r\n        <span style=\"color: #408080; font-style: italic;\">\/\/\u68c0\u67e5\u52a0\u5bc6key\uff0civ\u7684\u957f\u5ea6\u662f\u5426\u7b26\u5408\u7b97\u6cd5\u8981\u6c42  <\/span>\r\n        <span style=\"color: #19177c;\">$key<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">fixLen<\/span>(<span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">_key<\/span>, <span style=\"color: #008000;\">mcrypt_enc_get_key_size<\/span>(<span style=\"color: #19177c;\">$td<\/span>));  \r\n        <span style=\"color: #19177c;\">$iv<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">fixLen<\/span>(<span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">_iv<\/span>, <span style=\"color: #008000;\">mcrypt_enc_get_iv_size<\/span>(<span style=\"color: #19177c;\">$td<\/span>));  \r\n          \r\n        <span style=\"color: #408080; font-style: italic;\">\/\/\u52a0\u5bc6\u6570\u636e\u957f\u5ea6\u5904\u7406  <\/span>\r\n        <span style=\"color: #19177c;\">$str<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">strPad<\/span>(<span style=\"color: #19177c;\">$str<\/span>, <span style=\"color: #008000;\">mcrypt_enc_get_block_size<\/span>(<span style=\"color: #19177c;\">$td<\/span>));  \r\n          \r\n        <span style=\"color: #008000; font-weight: bold;\">if<\/span> (<span style=\"color: #008000;\">mcrypt_generic_init<\/span>(<span style=\"color: #19177c;\">$td<\/span>, <span style=\"color: #19177c;\">$key<\/span>, <span style=\"color: #19177c;\">$iv<\/span>) <span style=\"color: #666666;\">!==<\/span> <span style=\"color: #666666;\">0<\/span>) {  \r\n            <span style=\"color: #008000; font-weight: bold;\">return<\/span> <span style=\"color: #008000; font-weight: bold;\">false<\/span>;  \r\n        }  \r\n        <span style=\"color: #19177c;\">$result<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #008000;\">mcrypt_generic<\/span>(<span style=\"color: #19177c;\">$td<\/span>, <span style=\"color: #19177c;\">$str<\/span>);  \r\n        <span style=\"color: #008000;\">mcrypt_generic_deinit<\/span>(<span style=\"color: #19177c;\">$td<\/span>);  \r\n        <span style=\"color: #008000;\">mcrypt_module_close<\/span>(<span style=\"color: #19177c;\">$td<\/span>);  \r\n        <span style=\"color: #008000; font-weight: bold;\">return<\/span> <span style=\"color: #19177c;\">$result<\/span>;  \r\n    }  \r\n      \r\n    <span style=\"color: #ba2121; font-style: italic;\">\/** <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * \u5bf9\u52a0\u5bc6\u7684\u5b57\u7b26\u4e32\u8fdb\u884c3DES\u89e3\u5bc6 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @param string \u8981\u89e3\u5bc6\u7684\u5b57\u7b26\u4e32 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @return mixed \u52a0\u5bc6\u6210\u529f\u8fd4\u56de\u52a0\u5bc6\u540e\u7684\u5b57\u7b26\u4e32\uff0c\u5426\u5219\u8fd4\u56defalse <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    *\/<\/span>  \r\n    <span style=\"color: #008000; font-weight: bold;\">public<\/span> <span style=\"color: #008000; font-weight: bold;\">function<\/span> <span style=\"color: #0000ff;\">decrypt3DES<\/span>(<span style=\"color: #19177c;\">$str<\/span>)  \r\n    {  \r\n        <span style=\"color: #19177c;\">$td<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #008000;\">mcrypt_module_open<\/span>(MCRYPT_3DES, <span style=\"color: #ba2121;\">\"\"<\/span>, MCRYPT_MODE_CBC, <span style=\"color: #ba2121;\">\"\"<\/span>);  \r\n        <span style=\"color: #008000; font-weight: bold;\">if<\/span> (<span style=\"color: #19177c;\">$td<\/span> <span style=\"color: #666666;\">===<\/span> <span style=\"color: #008000; font-weight: bold;\">false<\/span>) {  \r\n            <span style=\"color: #008000; font-weight: bold;\">return<\/span> <span style=\"color: #008000; font-weight: bold;\">false<\/span>;  \r\n        }  \r\n          \r\n        <span style=\"color: #408080; font-style: italic;\">\/\/\u68c0\u67e5\u52a0\u5bc6key\uff0civ\u7684\u957f\u5ea6\u662f\u5426\u7b26\u5408\u7b97\u6cd5\u8981\u6c42  <\/span>\r\n        <span style=\"color: #19177c;\">$key<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">fixLen<\/span>(<span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">_key<\/span>, <span style=\"color: #008000;\">mcrypt_enc_get_key_size<\/span>(<span style=\"color: #19177c;\">$td<\/span>));  \r\n        <span style=\"color: #19177c;\">$iv<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">fixLen<\/span>(<span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">_iv<\/span>, <span style=\"color: #008000;\">mcrypt_enc_get_iv_size<\/span>(<span style=\"color: #19177c;\">$td<\/span>));  \r\n          \r\n        <span style=\"color: #008000; font-weight: bold;\">if<\/span> (<span style=\"color: #008000;\">mcrypt_generic_init<\/span>(<span style=\"color: #19177c;\">$td<\/span>, <span style=\"color: #19177c;\">$key<\/span>, <span style=\"color: #19177c;\">$iv<\/span>) <span style=\"color: #666666;\">!==<\/span> <span style=\"color: #666666;\">0<\/span>) {  \r\n            <span style=\"color: #008000; font-weight: bold;\">return<\/span> <span style=\"color: #008000; font-weight: bold;\">false<\/span>;  \r\n        }  \r\n          \r\n        <span style=\"color: #19177c;\">$result<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #008000;\">mdecrypt_generic<\/span>(<span style=\"color: #19177c;\">$td<\/span>, <span style=\"color: #19177c;\">$str<\/span>);  \r\n        <span style=\"color: #008000;\">mcrypt_generic_deinit<\/span>(<span style=\"color: #19177c;\">$td<\/span>);  \r\n        <span style=\"color: #008000;\">mcrypt_module_close<\/span>(<span style=\"color: #19177c;\">$td<\/span>);  \r\n          \r\n        <span style=\"color: #008000; font-weight: bold;\">return<\/span> <span style=\"color: #19177c;\">$this<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">strUnPad<\/span>(<span style=\"color: #19177c;\">$result<\/span>);  \r\n    }  \r\n      \r\n    <span style=\"color: #ba2121; font-style: italic;\">\/** <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * \u8fd4\u56de\u9002\u5408\u7b97\u6cd5\u957f\u5ea6\u7684key\uff0civ\u5b57\u7b26\u4e32 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @param string $str key\u6216iv\u7684\u503c <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @param int $td_len \u7b26\u5408\u6761\u4ef6\u7684key\u6216iv\u957f\u5ea6 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @return string \u8fd4\u56de\u5904\u7406\u540e\u7684key\u6216iv\u503c <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    *\/<\/span>  \r\n    <span style=\"color: #008000; font-weight: bold;\">private<\/span> <span style=\"color: #008000; font-weight: bold;\">function<\/span> <span style=\"color: #0000ff;\">fixLen<\/span>(<span style=\"color: #19177c;\">$str<\/span>, <span style=\"color: #19177c;\">$td_len<\/span>)  \r\n    {  \r\n        <span style=\"color: #19177c;\">$str_len<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #008000;\">strlen<\/span>(<span style=\"color: #19177c;\">$str<\/span>);  \r\n        <span style=\"color: #008000; font-weight: bold;\">if<\/span> (<span style=\"color: #19177c;\">$str_len<\/span> <span style=\"color: #666666;\">&gt;<\/span> <span style=\"color: #19177c;\">$td_len<\/span>) {  \r\n            <span style=\"color: #008000; font-weight: bold;\">return<\/span> <span style=\"color: #008000;\">substr<\/span>(<span style=\"color: #19177c;\">$str<\/span>, <span style=\"color: #666666;\">0<\/span>, <span style=\"color: #19177c;\">$td_len<\/span>);  \r\n        } <span style=\"color: #008000; font-weight: bold;\">else<\/span> <span style=\"color: #008000; font-weight: bold;\">if<\/span>(<span style=\"color: #19177c;\">$str_len<\/span> <span style=\"color: #666666;\">&lt;<\/span> <span style=\"color: #19177c;\">$td_len<\/span>) {  \r\n            <span style=\"color: #008000; font-weight: bold;\">return<\/span> <span style=\"color: #008000;\">str_pad<\/span>(<span style=\"color: #19177c;\">$str<\/span>, <span style=\"color: #19177c;\">$td_len<\/span>, <span style=\"color: #ba2121;\">'0'<\/span>);  \r\n        }  \r\n        <span style=\"color: #008000; font-weight: bold;\">return<\/span> <span style=\"color: #19177c;\">$str<\/span>;  \r\n    }  \r\n      \r\n    <span style=\"color: #ba2121; font-style: italic;\">\/** <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * \u8fd4\u56de\u9002\u5408\u7b97\u6cd5\u7684\u5206\u7ec4\u5927\u5c0f\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u672b\u5c3e\u4f7f\u7528\\0\u8865\u9f50 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @param string $str \u8981\u52a0\u5bc6\u7684\u5b57\u7b26\u4e32 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @param int $td_group_len \u7b26\u5408\u7b97\u6cd5\u7684\u5206\u7ec4\u957f\u5ea6 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @return string \u8fd4\u56de\u5904\u7406\u540e\u5b57\u7b26\u4e32 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    *\/<\/span>  \r\n    <span style=\"color: #008000; font-weight: bold;\">private<\/span> <span style=\"color: #008000; font-weight: bold;\">function<\/span> <span style=\"color: #0000ff;\">strPad<\/span>(<span style=\"color: #19177c;\">$str<\/span>, <span style=\"color: #19177c;\">$td_group_len<\/span>)  \r\n    {  \r\n        <span style=\"color: #19177c;\">$padding_len<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #19177c;\">$td_group_len<\/span> <span style=\"color: #666666;\">-<\/span> (<span style=\"color: #008000;\">strlen<\/span>(<span style=\"color: #19177c;\">$str<\/span>) <span style=\"color: #666666;\">%<\/span> <span style=\"color: #19177c;\">$td_group_len<\/span>);  \r\n        <span style=\"color: #008000; font-weight: bold;\">return<\/span> <span style=\"color: #008000;\">str_pad<\/span>(<span style=\"color: #19177c;\">$str<\/span>, <span style=\"color: #008000;\">strlen<\/span>(<span style=\"color: #19177c;\">$str<\/span>) <span style=\"color: #666666;\">+<\/span> <span style=\"color: #19177c;\">$padding_len<\/span>, <span style=\"color: #ba2121;\">\"<\/span><span style=\"color: #bb6622; font-weight: bold;\">\\0<\/span><span style=\"color: #ba2121;\">\"<\/span>);  \r\n    }  \r\n      \r\n    <span style=\"color: #ba2121; font-style: italic;\">\/** <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * \u8fd4\u56de\u9002\u5408\u7b97\u6cd5\u7684\u5206\u7ec4\u5927\u5c0f\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u672b\u5c3e\u4f7f\u7528\\0\u8865\u9f50 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @param string $str \u8981\u52a0\u5bc6\u7684\u5b57\u7b26\u4e32 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    * @return string \u8fd4\u56de\u5904\u7406\u540e\u5b57\u7b26\u4e32 <\/span>\r\n<span style=\"color: #ba2121; font-style: italic;\">    *\/<\/span>  \r\n    <span style=\"color: #008000; font-weight: bold;\">private<\/span> <span style=\"color: #008000; font-weight: bold;\">function<\/span> <span style=\"color: #0000ff;\">strUnPad<\/span>(<span style=\"color: #19177c;\">$str<\/span>)  \r\n    {  \r\n        <span style=\"color: #008000; font-weight: bold;\">return<\/span> <span style=\"color: #008000;\">rtrim<\/span>(<span style=\"color: #19177c;\">$str<\/span>);  \r\n    }  \r\n}  \r\n<span style=\"color: #19177c;\">$key<\/span>   <span style=\"color: #666666;\">=<\/span> <span style=\"color: #ba2121;\">'ABCEDFGHIJKLMNOPQ'<\/span>;  \r\n<span style=\"color: #19177c;\">$iv<\/span>    <span style=\"color: #666666;\">=<\/span> <span style=\"color: #ba2121;\">'0123456789'<\/span>;  \r\n<span style=\"color: #19177c;\">$des<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #008000; font-weight: bold;\">new<\/span> Encrypt(<span style=\"color: #19177c;\">$key<\/span>, <span style=\"color: #19177c;\">$iv<\/span>);  \r\n<span style=\"color: #19177c;\">$str<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #ba2121;\">\"abcdefghijklmnopq\"<\/span>;  \r\n<span style=\"color: #19177c;\">$e_str<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #19177c;\">$des<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">encrypt3DES<\/span>(<span style=\"color: #19177c;\">$str<\/span>);  \r\n<span style=\"color: #008000; font-weight: bold;\">echo<\/span> <span style=\"color: #19177c;\">$e_str<\/span>;\r\n<span style=\"color: #19177c;\">$d_str<\/span> <span style=\"color: #666666;\">=<\/span> <span style=\"color: #19177c;\">$des<\/span><span style=\"color: #666666;\">-&gt;<\/span><span style=\"color: #7d9029;\">decrypt3DES<\/span>(<span style=\"color: #19177c;\">$e_str<\/span>);  \r\n<span style=\"color: #008000; font-weight: bold;\">echo<\/span> <span style=\"color: #ba2121;\">'='<\/span><span style=\"color: #666666;\">.<\/span><span style=\"color: #19177c;\">$d_str<\/span>;\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>3DES\uff08\u6216\u79f0\u4e3aTriple DES\uff09\u662f\u4e09\u91cd\u6570\u636e\u52a0\u5bc6\u7b97\u6cd5\uff08TDEA\uff0cTriple Data Encryptio [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":309,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[6],"class_list":["post-307","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP\u4f7f\u75283DES\u7b97\u6cd5\u52a0\u5bc6\u89e3\u5bc6\u5b57\u7b26\u4e32 | \u98ce\u96e8\u65e0\u963bblog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fengyuwuzu.cn\/?p=307\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP\u4f7f\u75283DES\u7b97\u6cd5\u52a0\u5bc6\u89e3\u5bc6\u5b57\u7b26\u4e32 | \u98ce\u96e8\u65e0\u963bblog\" \/>\n<meta property=\"og:description\" content=\"3DES\uff08\u6216\u79f0\u4e3aTriple DES\uff09\u662f\u4e09\u91cd\u6570\u636e\u52a0\u5bc6\u7b97\u6cd5\uff08TDEA\uff0cTriple Data Encryptio [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fengyuwuzu.cn\/?p=307\" \/>\n<meta property=\"og:site_name\" content=\"\u98ce\u96e8\u65e0\u963bblog\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-21T02:27:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fengyuwuzu.cn\/wp-content\/uploads\/2017\/12\/timg.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"500\" \/>\n\t<meta property=\"og:image:height\" content=\"326\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"\u98ce\u96e8\u65e0\u963b\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u98ce\u96e8\u65e0\u963b\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fengyuwuzu.cn\/?p=307\",\"url\":\"https:\/\/fengyuwuzu.cn\/?p=307\",\"name\":\"PHP\u4f7f\u75283DES\u7b97\u6cd5\u52a0\u5bc6\u89e3\u5bc6\u5b57\u7b26\u4e32 | \u98ce\u96e8\u65e0\u963bblog\",\"isPartOf\":{\"@id\":\"https:\/\/fengyuwuzu.cn\/#website\"},\"datePublished\":\"2017-12-21T02:27:53+00:00\",\"dateModified\":\"2017-12-21T02:27:53+00:00\",\"author\":{\"@id\":\"https:\/\/fengyuwuzu.cn\/#\/schema\/person\/34cd01f899e76e2afadb37539a184c9f\"},\"breadcrumb\":{\"@id\":\"https:\/\/fengyuwuzu.cn\/?p=307#breadcrumb\"},\"inLanguage\":\"zh-CN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fengyuwuzu.cn\/?p=307\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fengyuwuzu.cn\/?p=307#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/fengyuwuzu.cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP\u4f7f\u75283DES\u7b97\u6cd5\u52a0\u5bc6\u89e3\u5bc6\u5b57\u7b26\u4e32\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/fengyuwuzu.cn\/#website\",\"url\":\"https:\/\/fengyuwuzu.cn\/\",\"name\":\"\u98ce\u96e8\u65e0\u963b\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/fengyuwuzu.cn\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-CN\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/fengyuwuzu.cn\/#\/schema\/person\/34cd01f899e76e2afadb37539a184c9f\",\"name\":\"\u98ce\u96e8\u65e0\u963b\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-CN\",\"@id\":\"https:\/\/fengyuwuzu.cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/68e14230863f4533c3453c3dbd7675e7620bfe2f24de6f40d8089dd5ad6a419b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/68e14230863f4533c3453c3dbd7675e7620bfe2f24de6f40d8089dd5ad6a419b?s=96&d=mm&r=g\",\"caption\":\"\u98ce\u96e8\u65e0\u963b\"},\"description\":\"\u4e00\u4e2aWEB\u5f00\u53d1\u5de5\u7a0b\u5e08\uff01\u76ee\u524d\u6b63\u5728\u6df1\u5733\u67d0\u516c\u53f8\u4efb\u804c\uff01\",\"sameAs\":[\"http:\/\/fengyuwuzu.cn.com\"],\"url\":\"https:\/\/fengyuwuzu.cn\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP\u4f7f\u75283DES\u7b97\u6cd5\u52a0\u5bc6\u89e3\u5bc6\u5b57\u7b26\u4e32 | \u98ce\u96e8\u65e0\u963bblog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fengyuwuzu.cn\/?p=307","og_locale":"zh_CN","og_type":"article","og_title":"PHP\u4f7f\u75283DES\u7b97\u6cd5\u52a0\u5bc6\u89e3\u5bc6\u5b57\u7b26\u4e32 | \u98ce\u96e8\u65e0\u963bblog","og_description":"3DES\uff08\u6216\u79f0\u4e3aTriple DES\uff09\u662f\u4e09\u91cd\u6570\u636e\u52a0\u5bc6\u7b97\u6cd5\uff08TDEA\uff0cTriple Data Encryptio [&hellip;]","og_url":"https:\/\/fengyuwuzu.cn\/?p=307","og_site_name":"\u98ce\u96e8\u65e0\u963bblog","article_published_time":"2017-12-21T02:27:53+00:00","og_image":[{"width":500,"height":326,"url":"https:\/\/fengyuwuzu.cn\/wp-content\/uploads\/2017\/12\/timg.jpg","type":"image\/jpeg"}],"author":"\u98ce\u96e8\u65e0\u963b","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u98ce\u96e8\u65e0\u963b","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/fengyuwuzu.cn\/?p=307","url":"https:\/\/fengyuwuzu.cn\/?p=307","name":"PHP\u4f7f\u75283DES\u7b97\u6cd5\u52a0\u5bc6\u89e3\u5bc6\u5b57\u7b26\u4e32 | \u98ce\u96e8\u65e0\u963bblog","isPartOf":{"@id":"https:\/\/fengyuwuzu.cn\/#website"},"datePublished":"2017-12-21T02:27:53+00:00","dateModified":"2017-12-21T02:27:53+00:00","author":{"@id":"https:\/\/fengyuwuzu.cn\/#\/schema\/person\/34cd01f899e76e2afadb37539a184c9f"},"breadcrumb":{"@id":"https:\/\/fengyuwuzu.cn\/?p=307#breadcrumb"},"inLanguage":"zh-CN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fengyuwuzu.cn\/?p=307"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/fengyuwuzu.cn\/?p=307#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/fengyuwuzu.cn\/"},{"@type":"ListItem","position":2,"name":"PHP\u4f7f\u75283DES\u7b97\u6cd5\u52a0\u5bc6\u89e3\u5bc6\u5b57\u7b26\u4e32"}]},{"@type":"WebSite","@id":"https:\/\/fengyuwuzu.cn\/#website","url":"https:\/\/fengyuwuzu.cn\/","name":"\u98ce\u96e8\u65e0\u963b","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fengyuwuzu.cn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-CN"},{"@type":"Person","@id":"https:\/\/fengyuwuzu.cn\/#\/schema\/person\/34cd01f899e76e2afadb37539a184c9f","name":"\u98ce\u96e8\u65e0\u963b","image":{"@type":"ImageObject","inLanguage":"zh-CN","@id":"https:\/\/fengyuwuzu.cn\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/68e14230863f4533c3453c3dbd7675e7620bfe2f24de6f40d8089dd5ad6a419b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/68e14230863f4533c3453c3dbd7675e7620bfe2f24de6f40d8089dd5ad6a419b?s=96&d=mm&r=g","caption":"\u98ce\u96e8\u65e0\u963b"},"description":"\u4e00\u4e2aWEB\u5f00\u53d1\u5de5\u7a0b\u5e08\uff01\u76ee\u524d\u6b63\u5728\u6df1\u5733\u67d0\u516c\u53f8\u4efb\u804c\uff01","sameAs":["http:\/\/fengyuwuzu.cn.com"],"url":"https:\/\/fengyuwuzu.cn\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/fengyuwuzu.cn\/index.php?rest_route=\/wp\/v2\/posts\/307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fengyuwuzu.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fengyuwuzu.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fengyuwuzu.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fengyuwuzu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=307"}],"version-history":[{"count":2,"href":"https:\/\/fengyuwuzu.cn\/index.php?rest_route=\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":311,"href":"https:\/\/fengyuwuzu.cn\/index.php?rest_route=\/wp\/v2\/posts\/307\/revisions\/311"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fengyuwuzu.cn\/index.php?rest_route=\/wp\/v2\/media\/309"}],"wp:attachment":[{"href":"https:\/\/fengyuwuzu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fengyuwuzu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fengyuwuzu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}