Java MD5 getHexMd5(byte[] bytes)

Here you can find the source of getHexMd5(byte[] bytes)

Description

Get a hex representation of the MD5 checksum of an array of bytes.

License

Open Source License

Parameter

Parameter Description
bytes array of bytes

Return

lower-case hex digest of the input

Declaration

public static final String getHexMd5(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.xml.bind.DatatypeConverter;

public class Main {
    /**//www .j a  va  2s.  c o m
     * Get a hex representation of the MD5 checksum of an array of bytes.
     *
     * @param bytes
     *            array of bytes
     * @return lower-case hex digest of the input
     */
    public static final String getHexMd5(byte[] bytes) {
        MessageDigest digest = null;
        try {
            digest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            /**
             * This really, really cannot happen, because "MD5" = String
             * constant.
             */
        }
        digest.update(bytes);
        String md5 = DatatypeConverter.printHexBinary(digest.digest()).toLowerCase();
        return md5;
    }

    /**
     * @see #getHexMd5(byte[])
     * @param asText
     *            String to calculate the MD5 {@link MessageDigest} for
     */
    public static final String getHexMd5(String asText) {
        return getHexMd5(asText.getBytes());
    }
}

Related

  1. digestMd5(String plain)
  2. digestMD5(String text)
  3. encryptmd5(String str)
  4. generateMD5ByContent(String content)
  5. getFileMD5(String filePath)
  6. getMD5(File file)
  7. getMD5ByString(String orginalString)
  8. getMD5Checksum(String path)
  9. getMd5DigestHex(final String content)