Android MD5 Encode byteMd5(String plainText, Boolean is16)

Here you can find the source of byteMd5(String plainText, Boolean is16)

Description

byte Md

Declaration

public static String byteMd5(String plainText, Boolean is16) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static String byteMd5(String plainText, Boolean is16) {
        StringBuffer buf = new StringBuffer();
        try {//from  ww  w.  jav a 2s.  co  m
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            byte b[] = md.digest();
            int i;
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return is16 ? buf.toString().substring(8, 24) : buf.toString();
    }
}

Related

  1. checkDicMD5(String dicFile, final byte[] expected)
  2. MD5(String md5)
  3. getMD5Str(String str)
  4. MD5(String text)
  5. stringGetMD5String(String s)
  6. getMD5(byte[] source)
  7. md5(String string)
  8. createHMACWithMD5(String source, String key)
  9. md5(String text)