Java Hash Calculate getHashMDFive(String str)

Here you can find the source of getHashMDFive(String str)

Description

get Hash MD Five

License

Apache License

Declaration

public static String getHashMDFive(String str) throws RuntimeException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String getHashMDFive(String str) throws RuntimeException {
        try {//w w  w . j  a  v a  2s  .  com
            byte[] strBytes = str.getBytes("UTF-8");
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] hashByte = md.digest(strBytes);

            // Convert the byte to hex format
            StringBuilder sb = new StringBuilder();
            for (byte aHashByte : hashByte) {
                sb.append(Integer.toString((aHashByte & 0xff) + 0x100, 16).substring(1));
            }
            return sb.toString();
        } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. getHashKey(String input)
  2. getHashMD5(File file)
  3. getHashMD5(String arg)
  4. getHashMD5(String str)
  5. getHashMD5(String text)
  6. getHashOf(String s)
  7. getHashString()
  8. getHashString(byte[] data)
  9. getHashString(String password, String salt)