Java MD5 String md5(String data)

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

Description

Convert data to md5

License

Open Source License

Parameter

Parameter Description
data data to hash

Exception

Parameter Description
NoSuchAlgorithmException an exception

Return

hashed data

Declaration

public static String md5(String data) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.security.MessageDigest;

public class Main {
    /**/*  ww  w  .  ja  v  a  2 s .  c om*/
     * Convert data to md5
     * @param data data to hash
     * @return hashed data
     * @throws NoSuchAlgorithmException
     */
    public static String md5(String data) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(data.getBytes());

            return bytesToHex(md.digest());
        } catch (Exception ex) {

        }
        return "";
    }

    public static String bytesToHex(byte[] bytes) {
        StringBuffer result = new StringBuffer();
        for (byte byt : bytes)
            result.append(Integer.toString((byt & 0xff) + 0x100, 16).substring(1));
        return result.toString();
    }
}

Related

  1. md5(String content)
  2. md5(String content)
  3. md5(String content)
  4. md5(String d)
  5. md5(String data)
  6. md5(String data)
  7. md5(String data)
  8. md5(String data)
  9. md5(String encryptStr)