static boolean arraysEqual ( byte [ ] array1 , byte [ ] array2 ) { if ( array1 . length != array2 . length ) { return false ; } boolean isEqual = true ; for ( int i = 0 ; i < array1 . length ; i ++ ) { if ( array1 [ i ] != array2 [ i ] ) { isEqual = false ; } } return isEqual ; }
Compares arrays for equality in constant time . This avoids certain types of timing attacks .