Java MD5 String md5(String text)

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

Description

Encrypt String

License

Open Source License

Parameter

Parameter Description
text a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static String md5(String text) throws Exception 

Method Source Code


//package com.java2s;
/*/*from www  . j a va  2  s . c  o  m*/
 * Copyright (C) 2009-2015 SM2 SOFTWARE & SERVICES MANAGEMENT
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program has been created in the hope that it will be useful.
 * It is distributed WITHOUT ANY WARRANTY of any Kind,
 * without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 *
 * For more information, please contact SM2 Software & Services Management.
 * Mail: info@talaia-openppm.com
 * Web: http://www.talaia-openppm.com
 *
 * Module: utils
 * File: StringUtil.java
 * Create User: javier.hernandez
 * Create Date: 06/03/2015 14:35:37
 */

import java.security.MessageDigest;

public class Main {
    /**
     * Encrypt String
     * @param text
     * @return
     * @throws Exception
     */
    public static String md5(String text) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] b = md.digest(text.getBytes());
        int size = b.length;
        StringBuffer encryptStr = new StringBuffer(size);
        for (int i = 0; i < size; i++) {
            int u = b[i] & 255;
            if (u < 16) {
                encryptStr.append("0" + Integer.toHexString(u));
            } else {
                encryptStr.append(Integer.toHexString(u));
            }
        }
        return encryptStr.toString();
    }
}

Related

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