Java SHA1 SHA1Checksum(String filename)

Here you can find the source of SHA1Checksum(String filename)

Description

Calculate a SHA1 checksum of a file

License

Open Source License

Parameter

Parameter Description
filename a parameter

Exception

Parameter Description
NoSuchAlgorithmException an exception
IOException an exception

Declaration

public static byte[] SHA1Checksum(String filename)
        throws NoSuchAlgorithmException, IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;

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

public class Main {
    /**// w w w  .  j a v a 2  s. c o  m
     * Calculate a SHA1 checksum of a file
     * @param filename
     * @return
     * @throws NoSuchAlgorithmException
     * @throws IOException
     */
    public static byte[] SHA1Checksum(String filename)
            throws NoSuchAlgorithmException, IOException {
        InputStream fis = new FileInputStream(filename);

        byte[] buffer = new byte[1024];
        MessageDigest complete = MessageDigest.getInstance("SHA1");
        int numRead;
        while ((numRead = fis.read(buffer)) != -1) {
            complete.update(buffer, 0, numRead);
        }
        fis.close();
        return complete.digest();
    }
}

Related

  1. sha12String(MessageDigest messageDigest)
  2. sha1_b64(final String text)
  3. SHA1_HEX(byte[] bytes)
  4. sha1AsBytes(String input)
  5. sha1ByString(String str)
  6. sha1Digest(byte[] bytes)
  7. sha1Digest(byte[] bytes)
  8. sha1Digest(final InputStream data)
  9. sha1Digest(String src)