Here you can find the source of areEqual(final byte[] a, final byte[] b)
Parameter | Description |
---|---|
a | The first array. Must not be null . |
b | The second array. Must not be null . |
public static boolean areEqual(final byte[] a, final byte[] b)
//package com.java2s; //License from project: Apache License public class Main { /**/*from www. j a v a2 s . co m*/ * Checks the specified arrays for equality in constant time. Intended * to mitigate timing attacks. * * @param a The first array. Must not be {@code null}. * @param b The second array. Must not be {@code null}. * * @return {@code true} if the two arrays are equal, else * {@code false}. */ public static boolean areEqual(final byte[] a, final byte[] b) { // From http://codahale.com/a-lesson-in-timing-attacks/ if (a.length != b.length) { return false; } int result = 0; for (int i = 0; i < a.length; i++) { result |= a[i] ^ b[i]; } return result == 0; } }