Java MD5 Sum md5sum(byte[] content)

Here you can find the source of md5sum(byte[] content)

Description

mdsum

License

Open Source License

Declaration

public static String md5sum(byte[] content) throws NoSuchAlgorithmException 

Method Source Code

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

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String md5sum(byte[] content) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        byte[] md5raw = md5.digest(content);
        return md5ConvertDigest(md5raw);
    }//from  w  ww . j av  a2s.  c  o m

    public static String md5ConvertDigest(byte[] digest) {
        return toHex(digest, 32);
    }

    public static String toHex(byte[] digest, int length) {
        BigInteger bitInt = new BigInteger(1, digest);
        String hashText = bitInt.toString(16);

        while (hashText.length() < length) {
            hashText = "0" + hashText;
        }

        return hashText;
    }
}

Related

  1. md5sum(byte[] b)
  2. md5Sum(byte[] data)
  3. md5sum(byte[] input, int length)
  4. MD5Sum(byte[] par1Data)
  5. md5sum(File f)