Here you can find the source of SHA1Checksum(String filename)
Parameter | Description |
---|---|
filename | a parameter |
Parameter | Description |
---|---|
NoSuchAlgorithmException | an exception |
IOException | an exception |
public static byte[] SHA1Checksum(String filename) throws NoSuchAlgorithmException, IOException
//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(); } }