is Equal between two byte array - Android java.lang

Android examples for java.lang:Byte Array

Description

is Equal between two byte array

Demo Code

public class Main{

    public static boolean isEqual(byte[] digesta, byte[] digestb) {
        if (digesta.length != digestb.length) {
            return false;
        }/* ww  w .ja va 2s .co  m*/
        // Perform a constant time comparison to avoid timing attacks.
        int v = 0;
        for (int i = 0; i < digesta.length; i++) {
            v |= (digesta[i] ^ digestb[i]);
        }
        return v == 0;
    }

}

Related Tutorials