Java MD5 String md5(final String data)

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

Description

Creates the MD5 hash for a given string.

License

Open Source License

Parameter

Parameter Description
data The string to be hashed

Return

The MD5 hash (lowercase)

Declaration

public static String md5(final String data) 

Method Source Code

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

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    /**/*from w  w w.j  a v a 2 s .c  o m*/
     * Creates the MD5 hash for a given string.
     * 
     * @param data The string to be hashed
     * @return The MD5 hash (lowercase)
     */
    public static String md5(final String data) {
        final StringBuilder hash = new StringBuilder();

        try {
            final MessageDigest digester = MessageDigest.getInstance("MD5");
            final byte[] hashedData = digester.digest(data.getBytes());
            for (final byte b : hashedData) {
                hash.append(String.format("%02x", b));
            }
        } catch (final NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return hash.toString();
    }
}

Related

  1. md5(File file)
  2. md5(File file)
  3. md5(File gcdZipFile)
  4. md5(final File file)
  5. md5(final InputStream in)
  6. md5(final String inData)
  7. md5(final String input)
  8. md5(final String input)
  9. md5(final String message)