Here you can find the source of md5sum(String inString)
Parameter | Description |
---|---|
inString | Input string |
public static String md5sum(String inString)
//package com.java2s; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**//from w w w . j a v a2 s .c om * Calculate the MD5 checksum of the input string * @param inString Input string * @return MD5 checksum of the input string in hexadecimal value */ public static String md5sum(String inString) { MessageDigest algorithm = null; try { algorithm = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException nsae) { System.err.println("Cannot find digest algorithm"); return null; } byte[] defaultBytes = inString.getBytes(); algorithm.reset(); algorithm.update(defaultBytes); byte messageDigest[] = algorithm.digest(); return hexToString(messageDigest); } /** * Converts a byte array to string. * * @param data * Input byte array. * @return String */ public static String hexToString(byte[] data) { if (data == null) { return ""; } ; StringBuffer sb = new StringBuffer(data.length * 2); for (int i = 0; i < data.length; i++) { String hex = Integer.toHexString(0xFF & data[i]); if (hex.length() == 1) { sb.append('0'); } sb.append(hex); } return sb.toString().toUpperCase(); } /** * Converts object to a string.<br> * If object is null then return null * * @param obj * @return */ public static String toString(Object obj) { if (null == obj) { return null; } else { return obj.toString(); } } }