TOTP in Node with no packages: four steps, each checked against RFC 6238
When an authenticator code is rejected, the fault sits in one of four steps: decoding the secret, turning the clock into a counter, the HMAC, or the truncation to six digits. Writing those four steps yourself is the quickest way to know which one to look at. Here they are in Node with no packages, each with a known answer to check against. The known answer is the test vector from RFC 6238. Its…
Two of four steps in authenticator code generation are examined: the Base32 secret decoding and clock conversion to a counter. The ASCII text 12345678901234567890 serves as the secret, provided in Base32 format as GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ. The current Unix time in seconds is divided by the period (typically 30 seconds) and the result, rounded down, serves as the counter. This counter is represented as 8 bytes, written using big-endian notation.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to