Here you can find the source of md5(String message)
Parameter | Description |
---|---|
message | the message to encrypt |
public static String md5(String message)
//package com.java2s; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**//w w w .j a v a 2 s .com * Encrypt the passed String using MD5. * * @param message the message to encrypt * * @return the MD5 hash. */ public static String md5(String message) { try { MessageDigest md = MessageDigest.getInstance("MD5"); return (hex(md.digest(message.getBytes()))); } catch (NoSuchAlgorithmException e) { } return (null); } private static String hex(byte[] array) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; ++i) { String hexString = Integer.toHexString((array[i] & 0xFF) | 0x100); for (int j = 1; j < 3; j++) sb.append(Character.toUpperCase(hexString.charAt(j))); } return (sb.toString()); } }