Android SHA1 Hash Create generateDigest(byte[] inputBytes)

Here you can find the source of generateDigest(byte[] inputBytes)

Description

Generate a (SHA1) digest of the input bytes.

Parameter

Parameter Description
inputBytes a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static synchronized byte[] generateDigest(byte[] inputBytes)
        throws Exception 

Method Source Code

//package com.java2s;
import java.security.MessageDigest;

public class Main {
    private static MessageDigest digest = null;

    /**//w ww .  j  a  v a  2s.co  m
     * Generate a (SHA1) digest of the input bytes. The MessageDigest 
     * instance that backs this method is cached for efficiency.  
     * 
     * @param inputBytes
     * @return
     * @throws Exception
     */
    public static synchronized byte[] generateDigest(byte[] inputBytes)
            throws Exception {

        try {

            if (digest == null)
                digest = MessageDigest.getInstance("SHA-1");
            return digest.digest(inputBytes);

        } catch (Exception e) {
            throw new Exception("[SecUtil] Error in generating digest");

        }
    }
}

Related

  1. sha1(byte[] bytesOfMessage)
  2. getCertificateSHA1(X509Certificate certificate)
  3. hmacSha1(byte[] value, byte[] key)
  4. computeSHAHash(String password)
  5. encryptByUsingSha1(String passwd)