Java SHA256 sha256Digest(byte[] bytes)

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

Description

sha Digest

License

Apache License

Declaration

public static byte[] sha256Digest(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 final String SHA256_ALGORITHM_NAME = "SHA-256";

    public static byte[] sha256Digest(byte[] bytes) {
        return digest(SHA256_ALGORITHM_NAME, bytes);
    }/*from ww w .  j av a  2s .co  m*/

    private static byte[] digest(String algorithm, byte[] bytes) {
        return getDigest(algorithm).digest(bytes);
    }

    /**
     * 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. sha256(String text)
  2. SHA256(String texto)
  3. SHA256Binary(String toHash)
  4. SHA256byte(String input)
  5. sha256digest(@Nonnull byte[] data)
  6. sha256Digest(final InputStream data)
  7. sha256Encode(String message)
  8. sha256encrypt(String phrase)
  9. sha256Hash()