Java MD5 digestMD5(byte[] data)

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

Description

digest MD

License

Apache License

Declaration

public static byte[] digestMD5(byte[] data) 

Method Source Code

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

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static final String ALGORITHM_MD5 = "MD5";

    public static byte[] digestMD5(byte[] data) {
        return digest(data, ALGORITHM_MD5);
    }//w ww  .  j a  v a 2s.  c  o m

    public static byte[] digestMD5(byte[] data, byte[] salt) {
        if (data == null || salt == null) {
            return null;
        }
        byte[] dataSalt = new byte[data.length + salt.length];
        System.arraycopy(data, 0, dataSalt, 0, data.length);
        System.arraycopy(salt, 0, dataSalt, data.length, salt.length);
        return digestMD5(dataSalt);
    }

    public static byte[] digest(byte[] data, String algorithm) {
        if (data == null || data.length <= 0) {
            return null;
        }
        try {
            MessageDigest md = MessageDigest.getInstance(algorithm);
            md.update(data);
            return md.digest();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. byteArrayMD5(byte[] entity)
  2. core_md5(int[] K, int F)
  3. decodeMd5(String source)
  4. decryMd5(String source)
  5. digestMd5(final String value)
  6. digestMD5(String buffer, String key)
  7. digestMD5(String data)
  8. digestMD5(String login, String pass)