public static String hash ( Serializable obj ) { if ( obj == null ) { return "" ; } StringBuilder hexString = new StringBuilder ( ) ; try { MessageDigest m = MessageDigest . getInstance ( "SHA1" ) ; m . update ( SerializationUtils . serialize ( obj ) ) ; byte [ ] mdbytes = m . digest ( ) ; for ( byte mdbyte : mdbytes ) { hexString . append ( Integer . toHexString ( 0xFF & mdbyte ) ) ; } } catch ( NoSuchAlgorithmException e ) { return "" ; } return hexString . toString ( ) ; }
Create a hash of a serializable object