Java MD5 Byte Array MD5(byte[] source)

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

Description

MD

License

Apache License

Declaration

public static String MD5(byte[] source) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.security.MessageDigest;

public class Main {
    public static String MD5(byte[] source) {
        String s = null;//  w ww  . j  a v  a 2s.c  o  m
        char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        try {
            MessageDigest md = 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) {
                byte byte0 = tmp[i];
                str[(k++)] = hexDigits[(byte0 >>> 4 & 0xF)];

                str[(k++)] = hexDigits[(byte0 & 0xF)];
            }
            s = new String(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return s;
    }
}

Related

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