Java MD5 Byte Array md5(byte[] buf)

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

Description

md

License

Apache License

Declaration

public static String md5(byte[] buf) 

Method Source Code

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

import java.security.MessageDigest;

public class Main {
    public static String md5(byte[] buf) {
        String result = "";
        try {/*from  ww  w.j a  v a 2 s  . co  m*/
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(buf);
            result = toHex(md.digest());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    private static String toHex(byte[] digest) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < digest.length; ++i) {
            byte b = digest[i];
            int value = (b & 0x7F) + (b < 0 ? 128 : 0);
            buffer.append(value < 16 ? "0" : "");
            buffer.append(Integer.toHexString(value));
        }
        return buffer.toString();
    }
}

Related

  1. md5(byte data[])
  2. md5(byte data[])
  3. md5(byte[] buffer, int length)
  4. md5(byte[] bytes)
  5. md5(byte[] bytes)
  6. md5(byte[] bytes)