Java Digest digest(byte[] data, String algorithm)

Here you can find the source of digest(byte[] data, String algorithm)

Description

digest

License

Apache License

Declaration

private static String digest(byte[] data, String algorithm) 

Method Source Code

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

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

public class Main {
    private static String digest(byte[] data, String algorithm) {
        try {/*ww w.  ja va 2s  . com*/
            MessageDigest md = MessageDigest.getInstance(algorithm);
            byte[] digest = md.digest(data);
            StringBuilder buf = new StringBuilder();
            for (byte b : digest) {
                buf.append(Integer.toHexString(0xF & (b >> 4)));
                buf.append(Integer.toHexString(0xF & (b)));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalArgumentException(e);
        }
    }
}

Related

  1. digest(byte[] bytes)
  2. digest(byte[] bytes, String algorithm)
  3. digest(byte[] bytes, String algorithmName)
  4. digest(byte[] bytes, String txt)
  5. digest(byte[] data)
  6. digest(byte[] data, String algorithm)
  7. digest(byte[] input)
  8. digest(byte[] input, final String algorithm)
  9. digest(byte[] input, String algorithm, byte[] salt, int iterations)