Google身份验证器应用会生成令牌,我们尝试通过以下方式使用OTP库(otplib)进行复制。即使同时运行,一个匹配但另一个不匹配
import { authenticator, totp, hotp } from 'otplib'
const secret = "NZQKPMNENSPOWUQZ"
console.log(authenticator.generate(secret)) // matches the app token
console.log(totp.generate(secret)) // does not match
为什么两个生成的令牌不同?每个生成器的选项之间的区别是编码,因此也尝试了相同的结果
totp.options = {encoding: 'hex'} // default is 'ascii'
如何使用totp
(或hotp
)生成与authenticator
相同的代码