Java Hash Code Calculate generateHash(final String input)

Here you can find the source of generateHash(final String input)

Description

Generates a hashed string in MD5-format for the given string.

License

Open Source License

Parameter

Parameter Description
input a parameter

Declaration

public static String generateHash(final String input) 

Method Source Code

//package com.java2s;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    /**/*from   w  w w . jav a  2  s .c o  m*/
     * Generates a hashed string in MD5-format for the given string.
     * 
     * @param input
     * @return
     */
    public static String generateHash(final String input) {
        MessageDigest messageDigest;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(input.getBytes(), 0, input.length());
            return new BigInteger(1, messageDigest.digest()).toString(16);
        } catch (final NoSuchAlgorithmException e) {
            e.printStackTrace();
            throw new RuntimeException("No such hash algorithm!");
        }

    }
}

Related

  1. combineHashesUnsorted(final int a, final int b)
  2. generateHash(byte[] data)
  3. generateHash(char[] password, byte[] salt)
  4. generateHash(File file)
  5. generateHash(final String data)
  6. generateHash(final String msg, final String hashAlgorithm)
  7. generateHash(String algo, byte[]... bytes)
  8. generateHash(String input)
  9. generateHash(String input, String salt)