Android MD5 Encode md5Byte(String in)

Here you can find the source of md5Byte(String in)

Description

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

Parameter

Parameter Description
in - The String to be hashed.

Return

A byte array of the hashed input.

Declaration

public static byte[] md5Byte(String in) 

Method Source Code

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

public class Main {
    /**/*from  w  w w . ja v  a  2  s.  c  om*/
     * 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 s)
  2. md5(String str)
  3. md5(final String s)
  4. md5(final String s)
  5. md5(final String s)
  6. md5Byte(byte[] in)
  7. md5File(File file)
  8. md5Hex(String str)
  9. computeHashMD5(final String text)