Java MD5 Byte Array md5(byte[] data)

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

Description

Calculate the md5 hash value of a byte array

License

Open Source License

Parameter

Parameter Description
data the data

Return

the calculated hash as a 16 byte array

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 {
    /**//from  w ww .j  a v  a 2 s.  c  o  m
     * Calculate the md5 hash value of a byte array
     * 
     * @param data
     *            the data
     * @return the calculated hash as a 16 byte array
     */
    public static byte[] md5(byte[] data) {
        byte[] md5;
        // Calculate MD5
        try {
            MessageDigest md5Digest = MessageDigest.getInstance("MD5");
            md5Digest.update(data, 0, data.length);
            md5 = md5Digest.digest();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Couldn't generate MD5, not supported!");
        }

        return md5;
    }
}

Related

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