package com.gyarmy.test; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Md5Utils { public static String md5(String value){ String md5Str = ""; try { MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] myValue = value.getBytes(); byte[] md5Value = md5.digest(myValue); //输出md5的值 for(byte b : md5Value){ //System.out.print(Integer.toHexString(b)+" - "); int d = b & 0xff; String hexString = Integer.toHexString(d); if(hexString.length() == 1){ hexString = "0" + hexString; } //md5String.append(hexString); md5Str+=hexString; } } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } return md5Str+""; } }
0则评论给“md5加密代码”