Java Hash Code Calculate generateHash(String input)

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

Description

Pre: input!=null Post: Genera un Hash para el texto pasado.

License

Open Source License

Declaration

public static String generateHash(String input) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/* www  .  j a v a2s  .  c om*/
     * Pre: input!=null
     * Post: Genera un Hash para el texto pasado.
     * Fuente: http://viralpatel.net/blogs/java-md5-hashing-salting-password/
     */
    public static String generateHash(String input) {

        String md5 = null;

        if (null == input)
            return null;

        try {

            MessageDigest digest = MessageDigest.getInstance("MD5");

            digest.update(input.getBytes(), 0, input.length());

            md5 = new BigInteger(1, digest.digest()).toString(16);

        } catch (NoSuchAlgorithmException e) {

            e.printStackTrace();
        }
        return md5;
    }
}

Related

  1. generateHash(File file)
  2. generateHash(final String data)
  3. generateHash(final String input)
  4. generateHash(final String msg, final String hashAlgorithm)
  5. generateHash(String algo, byte[]... bytes)
  6. generateHash(String input, String salt)
  7. generateHash(String item)
  8. generateHash(String plaintext)
  9. generateHash(String plainText, String hashType)