Java Hash Calculate getHashKey(String input)

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

Description

get Hash Key

License

Open Source License

Declaration

public static byte[] getHashKey(String input) 

Method Source Code

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

import java.io.UnsupportedEncodingException;

import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static byte[] getHashKey(String input) {

        byte[] bytesOfMessage = null, digestMessage = null;
        ByteBuffer buffer = ByteBuffer.allocate(16);

        if (input == null) {
            buffer.putInt(0, 0);//from w w  w. ja va 2s .  c om
            return buffer.array();
        }

        try {
            bytesOfMessage = input.getBytes("UTF-8");
            MessageDigest md = MessageDigest.getInstance("MD5");
            digestMessage = md.digest(bytesOfMessage);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return digestMessage;
    }
}

Related

  1. getHash(String var)
  2. getHashChars(byte[] bytes)
  3. getHashedPassword(String plainPassword)
  4. getHashFromString(String str)
  5. getHashInstance(final String alg)
  6. getHashMD5(File file)
  7. getHashMD5(String arg)
  8. getHashMD5(String str)
  9. getHashMD5(String text)