Here you can find the source of md5String(String input)
public static String md5String(String input)
//package com.java2s; /*//from w w w . ja v a 2 s . c om * Copyright 2011 Dan Bjorge * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /** * MD5 hashes the given input string and returns the hex digest in String form. * * Input may not be null or empty. */ public static String md5String(String input) { String result = ""; MessageDigest algorithm; try { algorithm = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } algorithm.reset(); algorithm.update(input.getBytes()); byte[] md5 = algorithm.digest(); String tmp = ""; for (int i = 0; i < md5.length; i++) { tmp = (Integer.toHexString(0xFF & md5[i])); if (tmp.length() == 1) { result += "0" + tmp; } else { result += tmp; } } return result; } }