Java MD5 String md5(String input)

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

Description

Performs an md5 hash on the input string

License

Open Source License

Parameter

Parameter Description
input a parameter

Declaration

@SuppressWarnings("nls")
public static String md5(String input) 

Method Source Code

//package com.java2s;
/**//from  w  w  w.ja v  a 2 s . c  om
 * Copyright (c) 2012 Todoroo Inc
 *
 * See the file "LICENSE" for the full license governing this code.
 */

import java.math.BigInteger;

import java.security.MessageDigest;

public class Main {
    /**
     * Performs an md5 hash on the input string
     * @param input
     * @return
     */
    @SuppressWarnings("nls")
    public static String md5(String input) {
        try {
            byte[] bytesOfMessage = input.getBytes("UTF-8");
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] digest = md.digest(bytesOfMessage);
            BigInteger bigInt = new BigInteger(1, digest);
            String hashtext = bigInt.toString(16);
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            return hashtext;
        } catch (Exception e) {
            return "";
        }
    }
}

Related

  1. md5(String input)
  2. md5(String input)
  3. md5(String input)
  4. md5(String input)
  5. md5(String input)
  6. md5(String input)
  7. md5(String input)
  8. md5(String input)
  9. md5(String input)