Here you can find the source of md5Byte(byte[] in)
Parameter | Description |
---|---|
in | - The array of bytes to be hashed. |
public static byte[] md5Byte(byte[] in)
//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; } }