{"id":39,"date":"2023-07-14T13:42:58","date_gmt":"2023-07-14T05:42:58","guid":{"rendered":"https:\/\/blog.wystudio.xyz\/?p=39"},"modified":"2024-08-02T11:20:16","modified_gmt":"2024-08-02T03:20:16","slug":"java%e5%8e%9f%e5%88%9b%e4%b8%ad%e5%9b%bd%e7%ba%a2%e8%89%b2%e5%8a%a0%e5%af%86%f0%9f%87%a8%f0%9f%87%b3-%e5%8a%a0%e5%af%86%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.wystudio.xyz\/index.php\/2023\/07\/14\/java%e5%8e%9f%e5%88%9b%e4%b8%ad%e5%9b%bd%e7%ba%a2%e8%89%b2%e5%8a%a0%e5%af%86%f0%9f%87%a8%f0%9f%87%b3-%e5%8a%a0%e5%af%86%e7%ae%97%e6%b3%95\/","title":{"rendered":"[Java\u539f\u521b] \u4e13\u5c5e\u4e8e\u4e2d\u56fd\u4eba\u7684\u52a0\u5bc6\u65b9\u6cd5--\u7ea2\u8272\u52a0\u5bc6(\u5185\u9644\u5728\u7ebf\u6f14\u793a\u7f51\u7ad9)"},"content":{"rendered":"<h1>\u524d\u8a00<\/h1>\n<p>\u672c\u52a0\u5bc6\u65b9\u6cd5\u662f\u5728\u4f5c\u8005\u901b \u543e\u7231\u7834\u89e3\u8bba\u575b \u65f6\u7531\u4e00\u7bc7\u6587\u7ae0\u5f15\u53d1\u7684\u7075\u611f<a href=\"https:\/\/www.52pojie.cn\/\/thread-1690132-1-1.html\">\u3010\u524d\u7aef\u9006\u5411\u3011\u793e\u4f1a\u4e3b\u4e49\u6838\u5fc3\u4ef7\u503c\u89c2\u52a0\u5bc6\u65b9\u6cd5\u89e3\u6790+python\u7248\u590d\u73b0<\/a><br \/>\n\u8fd9\u7bc7\u6587\u7ae0\u4ecb\u7ecd\u4e86\u4e00\u79cd\u540d\u4e3a <code>\u793e\u4f1a\u4e3b\u4e49\u6838\u5fc3\u4ef7\u503c\u89c2\u52a0\u5bc6\u65b9\u6cd5<\/code> \u65e8\u5728\u901a\u8fc7\u7f16\u7a0b\u5b66\u4e60\u515a\u7684\u5341\u516b\u5927\u63d0\u51fa\u7684\u793e\u4f1a\u4e3b\u4e49\u6838\u5fc3\u4ef7\u503c\u89c2\u3002  <\/p>\n<p><strong><em>\u800c\u672c\u6587\u63d0\u5230\u7684\u52a0\u5bc6\u7b97\u6cd5\u7075\u611f\u6765\u81ea\u4e8e\u6b64\uff0c\u4f46\u52a0\u5bc6\u539f\u7406\u4e0e\u6b64\u52a0\u5bc6\u65b9\u6cd5\u5b8c\u5168\u4e0d\u540c<\/em><\/strong><\/p>\n<h1>\u7b97\u6cd5\u4ecb\u7ecd<\/h1>\n<p>\u4e2d\u56fd\u7ea2\u8272\u52a0\u5bc6\u662f\u4e00\u4e2a\u65b0\u578b\u52a0\u5bc6\u7b97\u6cd5\uff0c\u4e4b\u6240\u4ee5\u53d6\u8fd9\u4e2a\u540d\u5b57\uff0c\u90a3\u662f\u56e0\u4e3a\u52a0\u5bc6\u540e\u7684\u5bc6\u6587\u4ee5<strong><em>\u4e2d\u6587\u6c49\u5b57<\/em><\/strong>\u8f93\u51fa\uff0c\u4e14\u5185\u5bb9<strong><em>\u79ef\u6781\uff0c\u9633\u5149\uff0c\u5411\u4e0a<\/em><\/strong>\u3002  <\/p>\n<blockquote>\n<p>\u4f8b\u5982\uff1a<br \/>\n\u539f\u6587\u4e3a &quot;06&quot;<br \/>\n\u5219\u5bc6\u6587\u4e3a &quot;\u4e2d\u56fd&quot;  <\/p>\n<\/blockquote>\n<p><strong><em>\u6ce8\uff1a\u652f\u6301\u4e2d\u6587\u6c49\u5b57\uff0c\u82f1\u6587\uff0c\u6570\u5b57\uff0c\u4ee5\u53ca\u7279\u6b8a\u7b26\u53f7\u52a0\u5bc6<\/em><\/strong><\/p>\n<h1>\u7b97\u6cd5\u539f\u7406<\/h1>\n<h3>1.\u5c06\u539f\u6587\u8fdb\u884cURL\u7f16\u7801<\/h3>\n<p>\u76ee\u7684\uff1a\u5c06\u4e2d\u6587\u6c49\u5b57\u8f6c\u4e3a\u4f7f\u7528\u5b57\u6bcd+\u6570\u5b57\u66ff\u4ee3<\/p>\n<h3>2.\u8f6c\u4e3a\u5341\u516d\u8fdb\u5236<\/h3>\n<p>\u5c06\u4e0a\u4e00\u6b65\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u8f6c\u4e3a16\u8fdb\u5236\u6587\u672c(\u5c0f\u5199)<br \/>\n\u76ee\u7684\uff1a\u5c06\u6574\u4e2a\u5b57\u7b26\u4e32\u53d8\u4e3a\u53ea\u75316\u4e2a\u5b57\u6bcd<code>[a-f]<\/code>\u548c9\u4e2a\u6570\u5b57<code>[0-9]<\/code>\u7ec4\u6210<\/p>\n<h3>3.\u8f6c\u4e3achar[]\u6570\u7ec4<\/h3>\n<p>\u5c06\u4e0a\u4e00\u6b65\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u8f6c\u4e3a\u7531\u4e00\u4e2a\u4e00\u4e2a\u5b57\u7b26\u7ec4\u6210\u7684char[]\u6570\u7ec4<br \/>\n\u4f8b\u5982\uff1a&quot;123&quot; \u53d8\u6210 {&quot;1&quot;,&quot;2&quot;,&quot;3&quot;}<br \/>\n\u76ee\u7684\uff1a\u4e3a\u4e0b\u4e00\u6b65\u7684\u7d22\u5f15\u63d0\u4f9b\u51c6\u5907<\/p>\n<h3>4.\u904d\u5386char[]\u6570\u7ec4<\/h3>\n<p>\u904d\u5386\u4e0a\u4e00\u6b65\u5f97\u5230\u7684char[]\u6570\u7ec4\uff0c\u5c06\u6709\u4ee5\u4e0b\u4e24\u79cd\u60c5\u51b5\uff1a<\/p>\n<h4>\u2460\u904d\u5386\u5f97\u5230\u7684\u5143\u7d20\u4e3a[0-9]\u7684\u6570\u5b57<\/h4>\n<p>\u5c06\u6b64\u6570\u5b57\u4f5c\u4e3a\u7d22\u5f15\uff0c\u4ece <code>\u5e38\u91cf\u6587\u672c\u6570\u7ec4\u4e00<\/code> \u4e2d\u83b7\u53d6\u5143\u7d20<\/p>\n<blockquote>\n<p>\u5e38\u91cf\u6587\u672c\u6570\u7ec4\u4e00 = {&quot;\u4e2d&quot;,&quot;\u534e&quot;,&quot;\u4eba&quot;,&quot;\u6c11&quot;,&quot;\u5171&quot;,&quot;\u548c&quot;,&quot;\u56fd&quot;,&quot;\u4e07&quot;,&quot;\u5c81&quot;,&quot;\u653f&quot;}  <\/p>\n<\/blockquote>\n<p>\u5047\u5982\u6570\u5b57\u4e3a1\uff0c\u5219\u5f97\u5230&quot;\u534e&quot;<\/p>\n<h4>\u2461\u904d\u5386\u5f97\u5230\u7684\u5143\u7d20\u4e3a[a-f]\u7684\u5b57\u6bcd<\/h4>\n<p>\u5148\u83b7\u53d6\u8fd9\u4e2a\u5b57\u6bcd\u572826\u4e2a\u82f1\u6587\u5b57\u6bcd\u8868\u4e2d\u7684\u4f4d\u7f6e<br \/>\n\u5982a\u4e3a1\uff0cb\u4e3a2<br \/>\n\u5c06\u83b7\u53d6\u5230\u7684<strong><em>\u6570\u5b57\u51cf1<\/em><\/strong>\u4f5c\u4e3a\u7d22\u5f15\u3002\u4ece <code>\u5e38\u91cf\u6587\u672c\u6570\u7ec4\u4e8c<\/code> \u4e2d\u83b7\u53d6\u5143\u7d20  <\/p>\n<blockquote>\n<p>\u5e38\u91cf\u6587\u672c\u6570\u7ec4\u4e8c = {&quot;\u5bcc&quot;,&quot;\u5f3a&quot;,&quot;\u6587&quot;,&quot;\u660e&quot;,&quot;\u5e73&quot;,&quot;\u7b49&quot;}  <\/p>\n<\/blockquote>\n<p>\u5047\u5982\u5b57\u6bcd\u4e3ab\uff0c\u5219\u83b7\u53d6\u5230&quot;\u5f3a&quot;<\/p>\n<h3>5.\u62fc\u63a5\u5373\u53ef<\/h3>\n<p>\u5c06\u4e0a\u4e00\u6b65\u904d\u5386char[]\u6570\u7ec4\u4ece\u5e38\u91cf\u6587\u672c\u6570\u7ec4\u4e2d\u83b7\u53d6\u7684\u5143\u7d20\u62fc\u63a5\u8d77\u6765\uff0c\u6700\u540e\u8f93\u51fa\u5373\u4e3a\u5bc6\u6587  <\/p>\n<p><strong><em>\u89e3\u5bc6\u8fc7\u7a0b\u76f8\u53cd\u5373\u53ef<\/em><\/strong><\/p>\n<h1>\u7b97\u6cd5\u4ee3\u7801<\/h1>\n<pre><code class=\"language-java\">package xyz.wystudio.tool;\n\nimport java.util.regex.Matcher;\nimport java.net.URLEncoder;\nimport java.net.URLDecoder;\nimport java.io.UnsupportedEncodingException;\nimport java.util.regex.Pattern;\n\npublic class EncryptUtil {\n\n    private static final String[] LIST_CODE_EN = { &quot;\u5bcc&quot;, &quot;\u5f3a&quot;, &quot;\u6587&quot;, &quot;\u660e&quot;, &quot;\u5e73&quot;, &quot;\u7b49&quot; };\n    private static final String[] LIST_CODE_NUM = { &quot;\u4e2d&quot;, &quot;\u534e&quot;, &quot;\u4eba&quot;, &quot;\u6c11&quot;, &quot;\u5171&quot;, &quot;\u548c&quot;, &quot;\u56fd&quot;, &quot;\u4e07&quot;, &quot;\u5c81&quot;, &quot;\u7ea2&quot; };\n    private static final String[] LIST_HEX = { &quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot; };\n\n    public static String encode(String str) {\n        str = URLencode(str);\n        String hexString = StringtoHex(str);\n        return doInString(hexString);\n    }\n\n    public static String decode(String str) {\n        try {\n            StringBuffer sb = new StringBuffer();\n            char[] chars = str.toCharArray();\n            for (int i = 0; i &lt; chars.length; i++) {\n                if (findInNum(chars[i]) != -1) {\n                    sb.append(findInNum(chars[i]));\n                } else {\n                    if (findInEn(chars[i]) != -1) {\n                        sb.append(LIST_HEX[findInEn(chars[i])]);\n                    }\n                }\n            }\n            if(sb.toString().equals(&quot;&quot;) || sb.toString() == null){\n                return &quot;\u89e3\u5bc6\u5931\u8d25\u975e\u5bc6\u6587&quot;;\n            }\n            return URLdecode(HextoString(sb.toString()));\n        } catch (Exception e) {\n            return &quot;\u89e3\u5bc6\u5931\u8d25\u975e\u5bc6\u6587&quot;;\n        }\n    }\n\n    private static String StringtoHex(String str) {\n        StringBuffer sb = new StringBuffer();\n        \/\/\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\n        char ch[] = str.toCharArray();\n        for (int i = 0; i &lt; ch.length; i++) {\n            String hexString = Integer.toHexString(ch[i]);\n            sb.append(hexString);\n        }\n        String result = sb.toString();\n        return result;\n    }\n\n    private static String HextoString(String str) {\n        String result = new String();\n        char[] charArray = str.toCharArray();\n        for (int i = 0; i &lt; charArray.length; i = i + 2) {\n            String st = &quot;&quot; + charArray[i] + &quot;&quot; + charArray[i + 1];\n            char ch = (char) Integer.parseInt(st, 16);\n            result = result + ch;\n        }\n        return result;\n    }\n\n    private static String doInString(String str) {\n        StringBuffer sb = new StringBuffer();\n        char[] chars = str.toCharArray();\n        for (int i = 0; i &lt; chars.length; i++) {\n            if (isNum(chars[i])) {\n                sb.append(LIST_CODE_NUM[Integer.parseInt(chars[i] + &quot;&quot;)]);\n            } else {\n                sb.append(LIST_CODE_EN[EntoInt(chars[i]) - 1]);\n            }\n        }\n        return sb.toString();\n    }\n\n    private static boolean isNum(char str) {\n        Pattern pattern = Pattern.compile(&quot;[0-9]*&quot;);\n        Matcher isNum = pattern.matcher(str + &quot;&quot;);\n        if (!isNum.matches()) {\n            return false;\n        }\n        return true;\n    }\n\n    private static int EntoInt(char ch1) {\n        String str = ch1 + &quot;&quot;;\n        char ch = str.charAt(0);\n        int num = 0;\n        if (ch &gt;= &#039;a&#039; &amp;&amp; ch &lt;= &#039;z&#039;)\n            num = (int) ch - 96;\n        if (ch &gt;= &#039;A&#039; &amp;&amp; ch &lt;= &#039;Z&#039;)\n            num = (int) ch - 64;\n        return num;\n    }\n\n    private static int findInEn(char ch) {\n        String str = ch + &quot;&quot;;\n        int a = -1;\n        for (int i = 0; i &lt; LIST_CODE_EN.length; i++) {\n            if (LIST_CODE_EN[i].equals(str)) {\n                a = i;\n                break;\n            }\n        }\n        return a;\n    }\n\n    private static int findInNum(char ch) {\n        String str = ch + &quot;&quot;;\n        int a = -1;\n        for (int i = 0; i &lt; LIST_CODE_NUM.length; i++) {\n            if (LIST_CODE_NUM[i].equals(str)) {\n                a = i;\n                break;\n            }\n        }\n        return a;\n    }\n\n    private static String URLencode(String str) {\n        try {\n            return URLEncoder.encode(str, &quot;UTF-8&quot;);\n        } catch (UnsupportedEncodingException e) {\n            e.printStackTrace();\n            return str;\n        }\n    }\n\n    private static String URLdecode(String str) {\n        try {\n            return URLDecoder.decode(str, &quot;utf-8&quot;);\n        } catch (UnsupportedEncodingException e) {\n            e.printStackTrace();\n            return str;\n        }\n    }\n}<\/code><\/pre>\n<p>\u52a0\u5bc6\u65b9\u6cd5\u8c03\u7528<code>EncryptUtil.encode()<\/code>\u51fd\u6570\uff0c\u5e76\u4f20\u5165\u539f\u6587<br \/>\n\u89e3\u5bc6\u65b9\u6cd5\u8c03\u7528<code>EncryptUtil.decode()<\/code>\u51fd\u6570\uff0c\u5e76\u4f20\u5165\u5bc6\u6587<\/p>\n<h1>\u5728\u7ebf\u5c1d\u8bd5\u7f51\u7ad9<a href=\"https:\/\/api.wystudio.xyz\/wy\/ZGHSEncrypt\">https:\/\/api.wystudio.xyz\/wy\/ZGHSEncrypt<\/a><\/h1>\n<h1>\u5199\u5728\u6700\u540e<\/h1>\n<p>\u672c\u52a0\u5bc6\u7b97\u6cd5\u4ec5\u4f9b\u5b66\u4e60\u4ea4\u6d41\uff0c\u7981\u6b62\u7528\u4e8e\u975e\u6cd5\u7528\u9014  <\/p>\n<p>\u672c\u6587\u5df2\u540c\u6b65\u53d1\u81f3\u543e\u7231\u7834\u89e3\u8bba\u575b<a href=\"https:\/\/www.52pojie.cn\/thread-1808487-1-1.html\">\u7acb\u5373\u67e5\u770b<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u672c\u52a0\u5bc6\u65b9\u6cd5\u662f\u5728\u4f5c\u8005\u901b \u543e\u7231\u7834\u89e3\u8bba\u575b \u65f6\u7531\u4e00\u7bc7\u6587\u7ae0\u5f15\u53d1\u7684\u7075\u611f\u3010\u524d\u7aef\u9006\u5411\u3011\u793e\u4f1a\u4e3b\u4e49\u6838\u5fc3\u4ef7\u503c\u89c2\u52a0\u5bc6\u65b9\u6cd5\u89e3\u6790+p [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[8,9],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-java","tag-java","tag-9"],"_links":{"self":[{"href":"https:\/\/blog.wystudio.xyz\/index.php\/wp-json\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.wystudio.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wystudio.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wystudio.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wystudio.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":13,"href":"https:\/\/blog.wystudio.xyz\/index.php\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":52,"href":"https:\/\/blog.wystudio.xyz\/index.php\/wp-json\/wp\/v2\/posts\/39\/revisions\/52"}],"wp:attachment":[{"href":"https:\/\/blog.wystudio.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wystudio.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wystudio.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}