Crypto Lib
    Preparing search index...

    Function timingSafeEqual

    • Constant-time comparison of two byte arrays.

      Returns true only when both arrays have the same length and identical contents. The comparison always examines every byte regardless of where a mismatch occurs, preventing timing side-channel attacks.

      Parameters

      • a: Uint8Array

        First byte array to compare.

      • b: Uint8Array

        Second byte array to compare.

      Returns boolean

      true if a and b are identical, false otherwise.

      import { timingSafeEqual } from "@sebastienrousseau/crypto-lib";

      const mac1 = new Uint8Array([1, 2, 3]);
      const mac2 = new Uint8Array([1, 2, 3]);
      timingSafeEqual(mac1, mac2); // true