Java Hash Calculate getHash(String message)

Here you can find the source of getHash(String message)

Description

get Hash

License

Open Source License

Declaration

public static String getHash(String message) 

Method Source Code


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

import java.security.MessageDigest;

public class Main {
    public static String getHash(String message) {
        return getHash(message, "MD5");
    }//from   w  w w.ja va 2  s . c  o m

    public static String getHash(String message, String type) {
        StringBuilder sBuilder = null;
        try {
            MessageDigest messageDigest = MessageDigest.getInstance(type);
            messageDigest.update(message.getBytes());
            sBuilder = new StringBuilder();
            for (byte b : messageDigest.digest()) {
                sBuilder.append(String.format("%02X", b));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sBuilder.toString();
    }
}

Related

  1. getHash(String fileName, String hashType)
  2. getHash(String givenStr)
  3. getHash(String input)
  4. getHash(String input)
  5. getHash(String key)
  6. getHash(String pass, String algorithm)
  7. getHash(String password, byte[] salt)
  8. getHash(String password, byte[] salt)
  9. getHash(String password, String bsalt)