Java MD5 String md5(String input)

Here you can find the source of md5(String input)

Description

Returns a MD5 digest string of the input string.

License

LGPL

Parameter

Parameter Description
input the input string

Return

the MD5 digest string

Declaration

public static String md5(String input) 

Method Source Code

//package com.java2s;
/*/*from  w ww.j ava  2 s.c  om*/
 *   This software is distributed under the terms of the FSF 
 *   Gnu Lesser General Public License (see lgpl.txt). 
 *
 *   This program is distributed WITHOUT ANY WARRANTY. See the
 *   GNU General Public License for more details.
 */

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    /**
     * Returns a MD5 digest string of the input string.
     * 
     * @param input the input string
     * @return the MD5 digest string
     */
    public static String md5(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            BigInteger number = new BigInteger(1, md.digest(input
                    .getBytes()));
            String hashtext = number.toString(16);
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            return hashtext;
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. md5(String input)
  2. md5(String input)
  3. md5(String input)
  4. md5(String input)
  5. md5(String input)
  6. MD5(String inputString)
  7. md5(String inputText)
  8. md5(String inStr)
  9. md5(String key)