Java MD5 String md5ByHex(String src)

Here you can find the source of md5ByHex(String src)

Description

md By Hex

License

Apache License

Declaration

public static String md5ByHex(String src) 

Method Source Code

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

import java.security.MessageDigest;

public class Main {

    public static String md5ByHex(String src) {
        try {//w w  w. j a  v a  2s.c om
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] b = src.getBytes();
            md.reset();
            md.update(b);
            byte[] hash = md.digest();
            String hs = "";
            String stmp = "";
            for (int i = 0; i < hash.length; i++) {
                stmp = Integer.toHexString(hash[i] & 0xFF);
                if (stmp.length() == 1)
                    hs = hs + "0" + stmp;
                else {
                    hs = hs + stmp;
                }
            }
            return hs.toUpperCase();
        } catch (Exception e) {
            return "";
        }
    }
}

Related

  1. MD5(String... texts)
  2. md52(String string)
  3. MD5_HEX(String source)
  4. md5AsHexString(String text, String charset)
  5. md5Base64(String str)
  6. md5crypt(String s)
  7. md5Digest(final InputStream data)
  8. md5Digest(final String message)
  9. md5digest(String key)