com.atlassian.security.utils
Class ConstantTimeComparison

java.lang.Object
  extended by com.atlassian.security.utils.ConstantTimeComparison

public class ConstantTimeComparison
extends Object

This class provides some constant time comparison functions. It uses MessageDigest.isEqual, which since java 6u17 has been implemented using a constant time comparison.

Since:
v3.2

Method Summary
static boolean isEqual(byte[] a, byte[] b)
          A constant time comparison implementation of isEqual.
static boolean isEqual(String a, String b)
          A constant time comparison implementation of isEqual.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isEqual

public static boolean isEqual(byte[] a,
                              byte[] b)
                       throws NullPointerException
A constant time comparison implementation of isEqual.

Parameters:
a - a byte [] to compare.
b - another byte [] to compare.
Returns:
true if the two byte arrays are equal, otherwise false.
Throws:
NullPointerException - if either a or b are null.

isEqual

public static boolean isEqual(String a,
                              String b)
                       throws NullPointerException
A constant time comparison implementation of isEqual.

Parameters:
a - a String to compare.
b - another String to compare.
Returns:
true if the two Strings are equal, otherwise false.
Throws:
NullPointerException - if either a or b are null.


Copyright © 2013 Atlassian. All rights reserved.