Android MD5 Encode md5(String string)

Here you can find the source of md5(String string)

Description

md

Declaration

public static String md5(String string) 

Method Source Code

//package com.java2s;
import java.io.UnsupportedEncodingException;

import java.security.MessageDigest;

public class Main {
    public static String md5(String string) {
        if (string == null || string.trim().length() < 1) {
            return null;
        }//from ww  w. ja v a 2 s. c  o m
        try {
            return getMD5(string.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    private static String getMD5(byte[] source) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            StringBuffer result = new StringBuffer();
            for (byte b : md5.digest(source)) {
                result.append(Integer.toHexString((b & 0xf0) >>> 4));
                result.append(Integer.toHexString(b & 0x0f));
            }
            return result.toString();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}

Related

  1. getMD5Str(String str)
  2. MD5(String text)
  3. stringGetMD5String(String s)
  4. byteMd5(String plainText, Boolean is16)
  5. getMD5(byte[] source)
  6. createHMACWithMD5(String source, String key)
  7. md5(String text)
  8. encryptByUsingMd5(String passwd)
  9. md5(String input)