Java MD5 String md5Hex(String str)

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

Description

md Hex

License

Apache License

Declaration

public static String md5Hex(String str) throws Exception 

Method Source Code


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

import java.security.MessageDigest;

public class Main {

    public static String md5Hex(String str) throws Exception {
        if (str == null) {
            return null;
        }// w  w w  .  jav a 2 s .c om
        StringBuffer hexStrSb = new StringBuffer();
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] hash = md.digest(str.getBytes());
        for (int i = 0; i < hash.length; i++) {
            if ((0xff & hash[i]) < 0x10) {
                hexStrSb.append("0" + Integer.toHexString((0xFF & hash[i])));
            } else {
                hexStrSb.append(Integer.toHexString(0xFF & hash[i]));
            }
        }
        return hexStrSb.toString();
    }
}

Related

  1. md5Hex(String message)
  2. md5Hex(String message)
  3. md5Hex(String message)
  4. md5Hex(String s)
  5. md5hex(String source)
  6. md5raw(String data)
  7. md5Representation(String data)
  8. md5Signature(TreeMap params, String secret)
  9. md5Signature(TreeMap params, String secret)