Java MD5 String md5(String str)

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

Description

md

License

Open Source License

Declaration

public static String md5(String str) 

Method Source Code


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

public class Main {

    public static String md5(String str) {
        try {/*from  w ww  .  ja v a  2s  .c  o m*/
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes());

            byte[] b = md.digest();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < b.length; i++) {
                int v = (int) b[i];
                v = v < 0 ? 0x100 + v : v;
                String cc = Integer.toHexString(v);
                if (cc.length() == 1)
                    sb.append('0');
                sb.append(cc);
            }

            return sb.toString();
        } catch (Exception e) {
        }
        return "";
    }
}

Related

  1. md5(String str)
  2. md5(String str)
  3. MD5(String str)
  4. md5(String str)
  5. md5(String str)
  6. md5(String str)
  7. md5(String str)
  8. md5(String str)
  9. MD5(String str)