public static String sha1Hash ( File file ) throws IOException { try { DigestInputStream inputStream = new DigestInputStream ( new FileInputStream ( file ) , MessageDigest . getInstance ( "SHA-1" ) ) ; try { byte [ ] buffer = new byte [ 4098 ] ; while ( inputStream . read ( buffer ) != - 1 ) { // Read the entire stream } return bytesToHex ( inputStream . getMessageDigest ( ) . digest ( ) ) ; } finally { inputStream . close ( ) ; } } catch ( NoSuchAlgorithmException ex ) { throw new IllegalStateException ( ex ) ; } }
Generate a SHA . 1 Hash for a given file .