node.js - 如何计算 TOTP 到期的秒数?

标签 node.js security one-time-password google-authenticator

我正在使用 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/

相关文章:

node.js - 有没有类似 Azure 的 ServerSpec 的东西

javascript - 将 duktape 2.1.0 中的原生 C 模块加载到

javascript - 从链接加载 JSON 以在范围内使用

ios - ios cocoa touch静态库的独立沙箱

windows - 添加新文本字段 pGina

javascript - 如何使用带有 for 循环的 Node.js 和 Redis 分配全局变量?

javascript - 如何防止执行脚本但在 DOM 中显示它?

flash - 保护 Flash EXE

java - 我应该如何在棉花糖中添加权限请求?

java - Android 和服务器之间的 key 不同