Android MD5 Encode 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) 

Method Source Code

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

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    private static final char[] hexDigits = "0123456789abcdef"
            .toCharArray();/*ww w .  j  a  v  a  2 s .c  o m*/

    public static String md5Hex(String str) {
        final byte[] digested = md5(str);
        if (digested == null)
            return "";
        return toHex(digested);
    }

    public static byte[] md5(String str) {
        try {
            MessageDigest digest = MessageDigest.getInstance("md5");
            byte[] digested = digest.digest(str.getBytes());
            return digested;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static final String toHex(byte[] bytes) {
        StringBuilder sb = new StringBuilder(2 * bytes.length);
        for (byte b : bytes) {
            sb.append(hexDigits[(b >> 4) & 0xf]).append(hexDigits[b & 0xf]);
        }
        return sb.toString();
    }
}

Related

  1. md5(final String s)
  2. md5(final String s)
  3. md5Byte(String in)
  4. md5Byte(byte[] in)
  5. md5File(File file)
  6. computeHashMD5(final String text)
  7. getMD5String(File file)
  8. getMD5String(String str)
  9. getMd5(byte... values)