Java MD5 String md5(String plainText)

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

Description

MD5

License

GNU General Public License

Parameter

Parameter Description
plainText a parameter

Declaration


public static String md5(String plainText) 

Method Source Code

//package com.java2s;
/**/*from w w  w .j  a v  a  2 s  .co  m*/
 * License
 * 
 * Licensed under the GNU GPL v3
 * http://www.gnu.org/licenses/gpl.html
 * 
 */

import java.security.MessageDigest;

public class Main {
    /**
     * MD5
     * 
     * @param plainText
     * @return
     */

    public static String md5(String plainText) {
        return md5(plainText.getBytes());
    }

    public static String md5(byte[] plainText) {
        String result = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText);
            byte b[] = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            result = buf.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return result;
    }
}

Related

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