Java MD5 Byte Array md5(final byte[] bytes)

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

Description

Gets the given byte array's MD5 checksum, or null if unavailable.

License

Open Source License

Declaration

public static byte[] md5(final byte[] bytes) 

Method Source Code


//package com.java2s;

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

public class Main {
    /** Gets the given byte array's MD5 checksum, or null if unavailable. */
    public static byte[] md5(final byte[] bytes) {
        return digest("MD5", bytes);
    }//from   w  w w. j  a  v a  2  s  . c  om

    /**
     * Gets the given byte array's hash value according to the specified
     * algorithm.
     * 
     * @param algorithm The algorithm to use when generating the hash value.
     * @param bytes The byte array for which to compute the hash value.
     * @return The computed hash value, or null if the digest algorithm is not
     *         available.
     * @see MessageDigest
     */
    public static byte[] digest(final String algorithm, final byte[] bytes) {
        try {
            final MessageDigest digest = MessageDigest.getInstance(algorithm);
            digest.update(bytes);
            return digest.digest();
        } catch (final NoSuchAlgorithmException exc) {
            return null;
        }
    }
}

Related

  1. md5(byte[] source)
  2. md5(byte[] source)
  3. MD5(byte[] src)
  4. md5(byte[] str)
  5. md5(final byte[] b)
  6. md5(final byte[] data)
  7. md5Byte(String encryptStr)
  8. MD5Bytes(byte[] src)
  9. md5Bytes(String message)