Java MD5 Byte Array md5(byte[] source)

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

Description

md5 function

License

Open Source License

Parameter

Parameter Description
source the input buffer

Return

md5 string

Declaration

public static String md5(byte[] source) throws NoSuchAlgorithmException 

Method Source Code


//package com.java2s;

import java.security.NoSuchAlgorithmException;

public class Main {
    /**//from w ww.  j ava  2s  .com
     * md5 function
     *
     * @param source the input buffer
     * @return md5 string
     */
    public static String md5(byte[] source) throws NoSuchAlgorithmException {
        char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
        md.update(source);
        byte tmp[] = md.digest();
        char str[] = new char[32];
        int k = 0;
        for (int i = 0; i < 16; i++) {
            str[k++] = hexDigits[tmp[i] >>> 4 & 0xf];
            str[k++] = hexDigits[tmp[i] & 0xf];
        }

        return new String(str);
    }
}

Related

  1. md5(byte[] md5)
  2. md5(byte[] param)
  3. md5(byte[] source)
  4. MD5(byte[] source)
  5. md5(byte[] source)
  6. MD5(byte[] src)
  7. md5(byte[] str)
  8. md5(final byte[] b)
  9. md5(final byte[] bytes)