Java Hash Calculate getHash(String s)

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

Description

get Hash

License

Open Source License

Declaration

public static String getHash(String s) 

Method Source Code


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

import java.security.MessageDigest;

public class Main {
    public static String getHash(String s) {
        try {/*  ww w  .j  a v  a2 s.c o  m*/
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(s.getBytes());
            byte[] hashDigest = algorithm.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < hashDigest.length; i++) {
                String hex = Integer.toHexString(0xFF & hashDigest[i]);
                if (hex.length() == 1) {
                    hex = "0" + hex;
                }
                hexString.append(hex);
            }
            return hexString.toString();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getHash(String password, byte[] salt)
  2. getHash(String password, String bsalt)
  3. getHash(String password, String salt)
  4. getHash(String password, String salt)
  5. getHash(String phrase, String algorithm)
  6. getHash(String str, String algorithm)
  7. getHash(String strDate)
  8. getHash(String text)
  9. getHash(String valueToHash)