{"id":599,"date":"2015-04-29T19:52:21","date_gmt":"2015-04-29T11:52:21","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=599"},"modified":"2026-08-18T12:09:32","modified_gmt":"2026-08-18T04:09:32","slug":"%e4%b8%80%e4%b8%aa%e5%ae%9e%e7%8e%b0md5%e7%9a%84%e7%ae%80%e6%b4%81%e7%9a%84java%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=599","title":{"rendered":"\u4e00\u4e2a\u5b9e\u73b0MD5\u7684\u7b80\u6d01\u7684java\u7c7b"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">\u6d88\u606f\u6458\u8981\u6709<strong style=\"color: #4870ac;\">\u552f\u4e00\u6027<\/strong>\u548c<strong style=\"color: #4870ac;\">\u4e0d\u53ef\u9006<\/strong>\uff1a\u540c\u6837\u7684\u8f93\u5165\u5f97\u5230\u540c\u6837\u7684\u6458\u8981\uff0c\u5f88\u96be\u4ece\u6458\u8981\u53cd\u63a8\u539f\u6587\u3002MD5 \u5e38\u88ab\u62ff\u6765\u505a\u6821\u9a8c\uff0c\u65e7\u7cfb\u7edf\u91cc\u4e5f\u7528\u6765\u5904\u7406\u7528\u6237\u53e3\u4ee4\uff08\u73b0\u4ee3\u5bc6\u7801\u5b58\u50a8\u5e94\u4f7f\u7528\u4e13\u95e8\u7684\u6162\u54c8\u5e0c\uff0c\u8fd9\u91cc\u6309\u539f\u6587\u7ed9\u51fa\u4e00\u4e2a\u7b80\u6d01\u5b9e\u73b0\uff09\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u4e0b\u9762\u8fd9\u4e2a <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">StringUtil<\/code> \u628a\u4efb\u610f\u5b57\u7b26\u4e32\u7f16\u6210 32 \u4f4d\u5341\u516d\u8fdb\u5236 MD5\u3002<\/p>\n<p><!--more--><\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u5b9e\u73b0\u7c7b<\/h2>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">package test;\nimport java.security.MessageDigest;\n\npublic class StringUtil {\n\n    private final static String[] hexDigits = {\n        \"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\",\n        \"8\", \"9\", \"a\", \"b\", \"c\", \"d\", \"e\", \"f\"\n    };\n\n    \/**\n     * \u8f6c\u6362\u5b57\u8282\u6570\u7ec4\u4e3a 16 \u8fdb\u5236\u5b57\u4e32\n     * @param b \u5b57\u8282\u6570\u7ec4\n     * @return 16 \u8fdb\u5236\u5b57\u4e32\n     *\/\n    public static String byteArrayToHexString(byte[] b) {\n        StringBuffer resultSb = new StringBuffer();\n        for (int i = 0; i &lt; b.length; i++) {\n            resultSb.append(byteToHexString(b[i]));\n        }\n        return resultSb.toString();\n    }\n\n    private static String byteToHexString(byte b) {\n        int n = b;\n        if (n &lt; 0)\n            n = 256 + n;\n        int d1 = n \/ 16;\n        int d2 = n % 16;\n        return hexDigits[d1] + hexDigits[d2];\n    }\n\n    public static String MD5Encode(String origin) {\n        String resultString = null;\n        try {\n            resultString = new String(origin);\n            MessageDigest md = MessageDigest.getInstance(\"MD5\");\n            resultString = byteArrayToHexString(md.digest(resultString.getBytes()));\n        } catch (Exception ex) {\n        }\n        return resultString;\n    }\n\n    public static void main(String[] args) {\n        System.err.println(MD5Encode(\"a\"));\n    }\n}<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u7528 RFC 1321 \u81ea\u6d4b<\/h2>\n<p style=\"margin: 1em 0px;\">RFC 1321 \u7ed9\u51fa\u4e86 Test suite\uff0c\u7528\u6765\u6838\u5bf9\u5b9e\u73b0\u662f\u5426\u6b63\u786e\uff1a<\/p>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u8f93\u5165<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">MD5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">\"\"<\/code>\uff08\u7a7a\u4e32\uff09<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">d41d8cd98f00b204e9800998ecf8427e<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">\"a\"<\/code><\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">0cc175b9c0f1b6a831c399e269772661<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">\"abc\"<\/code><\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">900150983cd24fb0d6963f7d28e17f72<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">\"message digest\"<\/code><\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">f96b697d7cb7938d525a2f31aaf161d0<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">\"abcdefghijklmnopqrstuvwxyz\"<\/code><\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">c3fcd3d76192e4007dfb496cca67e13b<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 1em 0px;\">\u4e3b\u65b9\u6cd5\u6253\u5370 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">MD5Encode(\"a\")<\/code>\uff0c\u5bf9\u7167\u8868\u4e2d\u7b2c\u4e8c\u884c\u5373\u53ef\u3002<\/p>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1aMD5 \u662f\u6458\u8981\u4e0d\u662f\u53ef\u9006\u52a0\u5bc6\uff1a\u540c\u4e00\u539f\u6587\u540c\u4e00\u7ed3\u679c\uff0c\u7528 RFC 1321 \u90a3\u7ec4\u5411\u91cf\u5c31\u80fd\u9a8c\u8bc1\u81ea\u5df1\u7684\u5b9e\u73b0\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u6d88\u606f\u6458\u8981\u6709\u552f\u4e00\u6027\u548c\u4e0d\u53ef\u9006\uff1a\u540c\u6837\u7684\u8f93\u5165\u5f97\u5230\u540c\u6837\u7684\u6458\u8981\uff0c\u5f88\u96be\u4ece\u6458\u8981\u53cd\u63a8\u539f\u6587\u3002MD5 \u5e38\u88ab\u62ff\u6765\u505a\u6821\u9a8c\uff0c\u65e7\u7cfb\u7edf\u91cc\u4e5f\u7528\u6765 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[43,57],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/599"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=599"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/599\/revisions"}],"predecessor-version":[{"id":3738,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/599\/revisions\/3738"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}