Java MD5 Byte Array md5(byte[] data)

Here you can find the source of md5(byte[] data)

Description

Calculates the MD5 digest and returns the symbol as a 16 element byte[].

License

Open Source License

Parameter

Parameter Description
data Data to digest

Return

MD5 digest

Declaration

public static byte[] md5(byte[] data) 

Method Source Code

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

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

public class Main {
    public static final String MD5_ALGORITHM = "MD5";

    /**/*from   www.ja  v a  2s.c  o m*/
     * Calculates the MD5 digest and returns the symbol as a 16 element
     * <code>byte[]</code>.
     *
     * @param data Data to digest
     * @return MD5 digest
     */
    public static byte[] md5(byte[] data) {
        return getMD5().digest(data);
    }

    /**
     * Calculates the MD5 digest and returns the symbol as a 16 element
     * <code>byte[]</code>.
     *
     * @param data Data to digest
     * @return MD5 digest
     */
    public static byte[] md5(String data) {
        return md5(data.getBytes());
    }

    /**
     * Returns an MD5 MessageDigest.
     *
     * @return An MD5 digest creating.
     * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught,
     */
    private static MessageDigest getMD5() {
        return getMessageDigest(MD5_ALGORITHM);
    }

    public static MessageDigest getMessageDigest(String algorithm) {
        try {
            return MessageDigest.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e.getMessage());
        }
    }
}

Related

  1. md5(byte[] bytes)
  2. md5(byte[] bytes)
  3. md5(byte[] data)
  4. md5(byte[] data)
  5. md5(byte[] data)
  6. md5(byte[] data)
  7. md5(byte[] input)
  8. md5(byte[] input)
  9. md5(byte[] input)