Java SHA1 sha1Digest(byte[] bytes)

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

Description

sha Digest

License

Apache License

Declaration

public static byte[] sha1Digest(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 SHA1_ALGORITHM_NAME = "SHA-1";

    public static byte[] sha1Digest(byte[] bytes) {
        return digest(SHA1_ALGORITHM_NAME, bytes);
    }//  w w  w .j a v a2  s  .c o 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. sha1_b64(final String text)
  2. SHA1_HEX(byte[] bytes)
  3. sha1AsBytes(String input)
  4. sha1ByString(String str)
  5. SHA1Checksum(String filename)
  6. sha1Digest(byte[] bytes)
  7. sha1Digest(final InputStream data)
  8. sha1Digest(String src)
  9. sha1DigestAsHex(String data)