Java MD5 Byte Array md5(byte[] md5)

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

Description

md

License

Apache License

Declaration

public static byte[] md5(byte[] md5) 

Method Source Code


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

import java.security.MessageDigest;

public class Main {
    public static byte[] md5(byte[] md5) {
        try {/*  w ww  . j av  a 2 s . co  m*/
            return MessageDigest.getInstance("MD5").digest(md5);
        } catch (Exception e) {

        }
        return md5;
    }

    public static String md5(String str) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes());
            byte b[] = md.digest();

            int i;

            StringBuilder buf = new StringBuilder("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            str = buf.toString();
        } catch (Exception e) {
            e.printStackTrace();

        }
        return str;
    }
}

Related

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