Java MD5 Byte Array md5(byte[] bytes)

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

Description

md

License

Apache License

Declaration

public static String md5(byte[] bytes) 

Method Source Code


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

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

public class Main {
    public static String md5(byte[] bytes) {
        try {/*www .j a  va  2  s  .  c o  m*/
            MessageDigest d = MessageDigest.getInstance("MD5");
            byte[] array = d.digest(bytes);

            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < array.length; ++i) {
                sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
            }
            return sb.toString();

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return createId();
        }
    }

    public static String createId() {
        return UUID.randomUUID().toString().substring(0, 8);
    }
}

Related

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