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

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

Description

digest

License

Apache License

Declaration

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

Method Source Code

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

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

public class Main {
    private static byte[] digest(String algorithm, byte[] bytes) {
        return getDigest(algorithm).digest(bytes);
    }//w  ww. j a  va  2s  .  c o  m

    /**
     * Creates a new {@link MessageDigest} with the given algorithm. Necessary
     * because {@code MessageDigest} is not thread-safe.
     */
    private static MessageDigest getDigest(String algorithm) {
        try {
            return MessageDigest.getInstance(algorithm);
        } catch (NoSuchAlgorithmException ex) {
            throw new IllegalStateException("Could not find MessageDigest with algorithm \"" + algorithm + "\"",
                    ex);
        }
    }
}

Related

  1. digest(InputStream is, String digestAlgorithm)
  2. digest(MessageDigest digest, InputStream data)
  3. digest(MessageDigest method, File f)
  4. digest(Serializable object)
  5. digest(String alg, byte[] plainByte)
  6. digest(String algorithm, byte[] data)
  7. digest(String algorithm, String data)
  8. digest(String aValue)
  9. digest(String base)