Android MD5 Encode md5Byte(byte[] in)

Here you can find the source of md5Byte(byte[] in)

Description

Returns a byte array representation of the hash of a byte array input using the MD5 hashing algorithm.

Parameter

Parameter Description
in - The array of bytes to be hashed.

Return

A byte array representation of the input.

Declaration

public static byte[] md5Byte(byte[] in) 

Method Source Code

//package com.java2s;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    /**/*from  w  w  w .  j a v a  2s . c  o  m*/
     * Returns a byte array representation of the hash 
     * of a string input using the MD5 hashing algorithm.
     * 
     * @param in
     *            - The String to be hashed.
     * @return A byte array of the hashed input.
     */
    public static byte[] md5Byte(String in) {
        return digestByte("MD5", in.getBytes());
    }

    /**
     * Returns a byte array representation of the hash 
     * of a byte array input using the MD5 hashing algorithm.
     * 
     * @param in
     *            - The array of bytes to be hashed.
     * @return A byte array representation of the input.
     */
    public static byte[] md5Byte(byte[] in) {
        return digestByte("MD5", in);
    }

    /**
     * Returns a digest, in the form of an array of bytes, using various hashing
     * algorithms. This is a private function used by many of the public
     * functions within this class.
     * 
     * @param algorithm
     *            - The hashing algorithm to be used.
     * @param input
     *            - The array of bytes to be hashed.
     * @return An array of bytes representing the hash result.
     */
    private static byte[] digestByte(String algorithm, byte[] input) {
        MessageDigest m;
        try {
            m = MessageDigest.getInstance(algorithm);
            m.update(input, 0, input.length);
            return m.digest();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. md5(String str)
  2. md5(final String s)
  3. md5(final String s)
  4. md5(final String s)
  5. md5Byte(String in)
  6. md5File(File file)
  7. md5Hex(String str)
  8. computeHashMD5(final String text)
  9. getMD5String(File file)