Java MD5 String MD5(String str)

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

Description

MD

License

Apache License

Declaration

public static String MD5(String str) 

Method Source Code


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

import java.security.*;

public class Main {
    public static String MD5(String str) {
        if (str == null)
            return null;
        StringBuilder sb = new StringBuilder();
        try {/*w  ww .j a va 2s. com*/
            MessageDigest code = MessageDigest.getInstance("MD5");
            code.update(str.getBytes());
            byte[] bs = code.digest();
            for (int i = 0; i < bs.length; i++) {
                int v = bs[i] & 0xFF;
                if (v < 16)
                    sb.append(0);
                sb.append(Integer.toHexString(v));
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return sb.toString().toUpperCase();
    }
}

Related

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