1
|
<br>转载自 |
1
|
http: //blog.csdn.net/randyjiawenjie/article/details/6589489
|
1
|
Golang的话直接,fmt.Sprintf( "%x" ,md5.Sum(nil))就可以了,JAVA里面好像没有格式化输出这样的函数
|
package czd.android.utils; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class MD5EncodeUtil { public static String MD5Encode(byte[] toencode) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(toencode); return HexEncode(md5.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; } public static String HexEncode(byte[] toencode) { StringBuilder sb = new StringBuilder(toencode.length * 2); for(byte b: toencode){ sb.append(Integer.toHexString((b & 0xf0) >>> 4)); sb.append(Integer.toHexString(b & 0x0f)); } return sb.toString().toUpperCase(); } }