1 import java.security.MessageDigest; 2 3 public class Demo { 4 5 public static void main(String[] args) throws Exception { 6 MessageDigest digest = MessageDigest.getInstance("md5"); 7 String pwd = "123456"; 8 byte[] result = digest.digest(pwd.getBytes()); 9 StringBuffer sb = new StringBuffer(); 10 for (int i = 0; i < result.length; i++) { 11 String str = Integer.toHexString((0xFF & result[i])); 12 if (str.length() == 1) { 13 sb.append("0" + str); 14 } else { 15 sb.append(str); 16 } 17 } 18 System.out.println(sb.toString()); 19 } 20 21 }
相关文章: