Java SHA1 sha1(final byte[] bytes)

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

Description

Gets the given byte array's SHA-1 checksum, or null if unavailable.

License

Open Source License

Declaration

public static byte[] sha1(final byte[] bytes) 

Method Source Code


//package com.java2s;

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

public class Main {
    /** Gets the given byte array's SHA-1 checksum, or null if unavailable. */
    public static byte[] sha1(final byte[] bytes) {
        return digest("SHA-1", bytes);
    }//  ww w  . jav  a  2 s .  c o  m

    /**
     * Gets the given byte array's hash value according to the specified
     * algorithm.
     * 
     * @param algorithm The algorithm to use when generating the hash value.
     * @param bytes The byte array for which to compute the hash value.
     * @return The computed hash value, or null if the digest algorithm is not
     *         available.
     * @see MessageDigest
     */
    public static byte[] digest(final String algorithm, final byte[] bytes) {
        try {
            final MessageDigest digest = MessageDigest.getInstance(algorithm);
            digest.update(bytes);
            return digest.digest();
        } catch (final NoSuchAlgorithmException exc) {
            return null;
        }
    }
}

Related

  1. SHA1(ByteBuffer buf, int offset, int size)
  2. sha1(File f)
  3. sha1(File file)
  4. sha1(File file)
  5. sha1(File sourceFile)
  6. sha1(final File file)
  7. sha1(final String data)
  8. sha1(final String str)
  9. sha1(final String string)