Here you can find the source of md5(final String input)
Parameter | Description |
---|---|
input | the string |
public static String md5(final String input)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Collection; public class Main { public static final String DELIMITER = ", "; /**//from w w w . j ava2 s . c om * Returns the MD5 of the given string * * @param input the string * @return the MD5 of the given string */ public static String md5(final String input) { if (null == input) { return null; } try { final MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(input.getBytes(), 0, input.length()); return new BigInteger(1, digest.digest()).toString(16); } catch (final NoSuchAlgorithmException e) { System.out.println("Could not create MD5! NoSuchAlgorithm: " + e.getMessage()); return null; } } /** * Returns the list of strings as a single string * @param list the list of strings * @param delimiter the delimiter * @return the list as string */ public static String toString(final Collection<String> list, final String delimiter) { final StringBuilder sb = new StringBuilder(); for (final String string : list) { sb.append(string).append(delimiter); } sb.setLength(sb.length() - delimiter.length()); return sb.toString(); } /** * Returns the list of strings as a single string * @param list the list of strings * @return the list as string */ public static String toString(final Collection<String> list) { return toString(list, DELIMITER); } }