Here you can find the source of md5(String input)
Parameter | Description |
---|---|
input | Input string. |
Parameter | Description |
---|---|
IllegalArgumentException | if input is blank. |
static String md5(String input)
//package com.java2s; //License from project: Apache License import java.security.MessageDigest; public class Main { /**/* w w w . j ava 2s .c o m*/ * Create an MD5 hash of a string. * * @param input Input string. * @return Hash of input. * @throws IllegalArgumentException if {@code input} is blank. */ static String md5(String input) { if (input == null || input.length() == 0) { throw new IllegalArgumentException("Input string must not be blank."); } try { MessageDigest algorithm = MessageDigest.getInstance("MD5"); algorithm.reset(); algorithm.update(input.getBytes()); byte[] messageDigest = algorithm.digest(); StringBuilder hexString = new StringBuilder(); for (byte messageByte : messageDigest) { hexString.append(Integer.toHexString((messageByte & 0xFF) | 0x100).substring(1, 3)); } return hexString.toString(); } catch (Exception e) { throw new RuntimeException(e); } } }