Java MD5 String MD5(String inputString)

Here you can find the source of MD5(String inputString)

Description

Used to get the MD5 hash of a given string.

License

Open Source License

Parameter

Parameter Description
inputString a parameter

Return

String containing MD5 hash or null if error caught

Declaration

public static String MD5(String inputString) 

Method Source Code

//package com.java2s;

import java.security.MessageDigest;

public class Main {
    /**//from ww w .j av a 2  s . c  o m
     * Used to get the MD5 hash of a given string.
     *
     * @param inputString
     * @return <code>String</code> containing MD5 hash or null if error caught
     */
    public static String MD5(String inputString) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            byte[] array = messageDigest.digest(inputString.getBytes());

            StringBuffer stringBuilder = new StringBuffer();

            for (int i = 0; i < array.length; ++i) {
                stringBuilder.append(Integer.toHexString(
                        (array[i] & 0xFF) | 0x100).substring(1, 3));
            }
            return stringBuilder.toString();
        } catch (java.security.NoSuchAlgorithmException e) {
        }

        return null;
    }
}

Related

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