Android MD5 Encode MD5(String s)

Here you can find the source of MD5(String s)

Description

MD

Declaration

public final static String MD5(String s) 

Method Source Code

//package com.java2s;
import java.security.MessageDigest;

public class Main {
    public final static String MD5(String s) {
        try {/*from  w w w.ja  v  a2  s.c  o m*/
            byte[] btInput = s.getBytes();
            MessageDigest mdInst = MessageDigest.getInstance("MD5");
            mdInst.update(btInput);
            byte[] md = mdInst.digest();
            StringBuilder sBuilder = bytesToHexString(md);
            return sBuilder.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static StringBuilder bytesToHexString(byte[] bytesArray) {
        if (bytesArray == null) {
            return null;
        }
        StringBuilder sBuilder = new StringBuilder();
        for (byte b : bytesArray) {
            String hv = String.format("%02x", b);
            sBuilder.append(hv);
        }
        return sBuilder;
    }
}

Related

  1. md5sum(String string)
  2. MD5(String str)
  3. MD5Encode(String origin)
  4. getMD5Code(String value)
  5. getMD5(String s)
  6. md5(final String s)
  7. md5(final String s)
  8. hexMD5(String input)
  9. getMD5(String str)