public static String sha1 ( File sourceFile ) throws Exception { byte [ ] buffer = new byte [ 1024 ] ; MessageDigest complete = MessageDigest . getInstance ( "SHA-1" ) ; updateDigest ( complete , sourceFile , buffer ) ; byte [ ] bytes = complete . digest ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( byte b : bytes ) { sb . append ( String . format ( "%02x" , b ) ) ; } return sb . toString ( ) ; }
Computes the hash of a file or directory .