Here you can find the source of md5Encode(String source)
Parameter | Description |
---|---|
source | String |
public static String md5Encode(String source)
//package com.java2s; import java.security.MessageDigest; public class Main { /**//from w ww . j a v a 2 s. c om * Get MD5 Encoding * * @param source {@link String} * @return String */ public static String md5Encode(String source) { try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] bytes = md.digest(source.getBytes("UTF-8")); return getHexString(bytes); } catch (Exception e) { e.printStackTrace(); return null; } } /** * Convert byte array to hex string * * @param bytes byte * @return String */ public static String getHexString(byte[] bytes) { StringBuffer stringBuffer = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { byte b = bytes[i]; String hex = Integer.toHexString(0x00FF & b); if (hex.length() == 1) { stringBuffer.append("0"); } stringBuffer.append(hex); } return stringBuffer.toString(); } }