Java MD5 String MD5(String pwd)

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

Description

MD

License

Apache License

Declaration

public static String MD5(String pwd) 

Method Source Code

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

import java.security.MessageDigest;

public class Main {
    private static char[] md5String = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
            'F' };

    public static String MD5(String pwd) {
        if (pwd != null) {
            try {
                byte[] btInput = pwd.getBytes();

                MessageDigest mdInst = MessageDigest.getInstance("MD5");

                mdInst.update(btInput);/*from  w w  w  . j av a  2  s  .c  o  m*/

                byte[] md = mdInst.digest();

                int j = md.length;

                char[] str = new char[j * 2];
                int k = 0;
                for (byte byte0 : md) {
                    str[(k++)] = md5String[(byte0 >>> 4 & 0xF)];
                    str[(k++)] = md5String[(byte0 & 0xF)];
                }

                return new String(str).toLowerCase();
            } catch (Exception e) {
                return null;
            }
        }
        return null;
    }
}

Related

  1. md5(String plainText)
  2. md5(String plainText)
  3. Md5(String plainText)
  4. Md5(String plainText)
  5. md5(String plainText)
  6. md5(String raw)
  7. MD5(String s)
  8. md5(String s)
  9. md5(String s)