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.
true
First byte array to compare.
Second byte array to compare.
true if a and b are identical, false otherwise.
a
b
false
import { timingSafeEqual } from "@sebastienrousseau/crypto-lib";const mac1 = new Uint8Array([1, 2, 3]);const mac2 = new Uint8Array([1, 2, 3]);timingSafeEqual(mac1, mac2); // true Copy
import { timingSafeEqual } from "@sebastienrousseau/crypto-lib";const mac1 = new Uint8Array([1, 2, 3]);const mac2 = new Uint8Array([1, 2, 3]);timingSafeEqual(mac1, mac2); // true
Constant-time comparison of two byte arrays.
Returns
trueonly 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.