我正在使用 notp
在我的 Node 应用程序中生成一个简单的 token :
var notp = require('notp')
notp.totp.gen("ciao", {}) // => 345678
我想构建一个类似于 Google Authenticator 提供的可视化效果,并且我需要知道生成的 otp 将过期的秒数(或日期时间)。
我该怎么做?
最佳答案
我已经找到了如何做到这一点,实际上非常简单,你只需要知道算法使用的启动时间即可。
事实证明,Google Authenticator 使用 Unix Epoch,因此在我的例子中,显示我可以执行的计时器:
setInterval(() => (console.log(30 - Math.round(new Date() / 1000) % 30)), 1000)
关于node.js - 如何计算 TOTP 到期的秒数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47160935/