Here you can find the source of md5(byte[] data)
byte[]
.
Parameter | Description |
---|---|
data | Data to digest |
public static byte[] md5(byte[] data)
//package com.java2s; //License from project: Open Source License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static final String MD5_ALGORITHM = "MD5"; /**/*from www.ja v a 2s.c o m*/ * Calculates the MD5 digest and returns the symbol as a 16 element * <code>byte[]</code>. * * @param data Data to digest * @return MD5 digest */ public static byte[] md5(byte[] data) { return getMD5().digest(data); } /** * Calculates the MD5 digest and returns the symbol as a 16 element * <code>byte[]</code>. * * @param data Data to digest * @return MD5 digest */ public static byte[] md5(String data) { return md5(data.getBytes()); } /** * Returns an MD5 MessageDigest. * * @return An MD5 digest creating. * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught, */ private static MessageDigest getMD5() { return getMessageDigest(MD5_ALGORITHM); } public static MessageDigest getMessageDigest(String algorithm) { try { return MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } } }