Android MD5 Encode getMD5Code(String value)

Here you can find the source of getMD5Code(String value)

Description

get MD Code

License

LGPL

Declaration

public static String getMD5Code(String value) 

Method Source Code

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

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

public class Main {
    public static String getMD5Code(String value) {
        if (value == null) {
            value = "";
        }//  w  ww  . ja v a 2  s  .  c om
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.reset();
            md.update(value.getBytes());
            byte[] md5Bytes = md.digest();
            StringBuffer hexValue = new StringBuffer();
            for (int i = 0; i < md5Bytes.length; i++) {
                int val = ((int) md5Bytes[i]) & 0xff;
                if (val < 16)
                    hexValue.append("0");
                hexValue.append(Integer.toHexString(val));
            }
            return hexValue.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. MD5Crypto(String str)
  2. stringToMD5(String string)
  3. md5sum(String string)
  4. MD5(String str)
  5. MD5Encode(String origin)
  6. getMD5(String s)
  7. MD5(String s)
  8. md5(final String s)
  9. md5(final String s)