Class HashCompareUtil

java.lang.Object
lib.pwss.hash.compare.util.HashCompareUtil

public final class HashCompareUtil extends Object
Utility class for comparing hashes.
  • Method Details

    • compareHashesXor

      public static boolean compareHashesXor(String oldHash, String newHash)
      Compares two hashes using an XOR operation on each corresponding character. This method checks if the provided old hash and new hash are identical by performing a bitwise XOR comparison on each corresponding position. If any position differs, it returns false; otherwise, it returns true.

      This is particularly useful for simple equality checks of fixed-length string representations such as checksums or cryptographic hashes where an exact match is required.

      Parameters:
      oldHash - the first hash to compare (must not be null)
      newHash - the second hash to compare (must not be null and should have the same length as oldHash)
      Returns:
      true if the hashes are identical, false otherwise
    • compareHashesXor

      public static boolean compareHashesXor(byte[] oldHash, byte[] newHash)
      Compares two hashes using an XOR operation on each corresponding byte. This method checks if the provided old hash and new hash are identical by performing a bitwise XOR comparison on each corresponding position. If any position differs, it returns false; otherwise, it returns true.

      This is particularly useful for simple equality checks of fixed-length string representations such as checksums or cryptographic hashes where an exact match is required.

      Parameters:
      oldHash - the first hash to compare (must not be null)
      newHash - the second hash to compare (must not be null and should have the same length as oldHash)
      Returns:
      true if the hashes are identical, false otherwise
    • compareHashesJavaEquals

      public static boolean compareHashesJavaEquals(String oldHash, String newHash)
      Compares two hashes using Java's built-in String.equals() method. This method checks if the provided old hash and new hash are identical by leveraging the standard equality comparison in Java. It returns true only if both hashes are not null and exactly match each other, otherwise it returns false.
      Parameters:
      oldHash - the first hash to compare (must not be null)
      newHash - the second hash to compare (must not be null)
      Returns:
      true if the hashes are identical, false otherwise
    • compareUsingXorAndJavaEquals

      public static boolean compareUsingXorAndJavaEquals(String oldHash, String newHash)
      Compares two hashes using both XOR operation and Java's built-in String.equals() method. This method performs a bitwise XOR comparison on each corresponding character of the hashes, then uses Java's standard equality check to ensure the hashes are identical in both ways.

      This combination ensures that not only do the string representations match exactly, but they also contain identical character codes at every position.

      Parameters:
      oldHash - the first hash to compare (must not be null)
      newHash - the second hash to compare (must not be null and should have the same length as oldHash)
      Returns:
      true if both comparisons are successful, false otherwise