crypto.timingSafeEqual()
A node:crypto function that compares two Buffers of equal length in a time that does not depend on where they differ.
In more detail
Use it to check HMAC signatures and tokens so the comparison leaks nothing through timing. It throws if the lengths differ, so compare the lengths first.
Related terms
- timing attack — An attack that works out secret information by measuring how long an operation takes.
- HMAC — A way of combining a secret key with a hash function to produce a tag that shows a message came from someone holding the key and was not changed.
- strict equality — Comparing two values with === or !==, which never convert either value to another type first, so values of different types are never equal.
Taught in
- Cryptographic Primitives: node:crypto & Ciphers — Node.js Internals & Backend Services