问题描述
在设备上:如果现在生成了TOTP,它会一直持续到最后几秒钟还是四舍五入到最接近的00?
On device: If a TOTP is generated now, does it go until the final seconds or does it do it rounded off to the nearest 00?
例如,如果我在22hr:30m:2s:33ms(在UTC中检查)生成了TOTP,它会四舍五入到22hr:30m:0s:00ms然后生成吗?
For example, if I generate a TOTP at 22hr:30m:2s:33ms (checked in UTC) is it rounded off to 22hr:30m:0s:00ms and then generated?
我有这个问题,因为,如果我要在22hr:30m:2s:33ms生成TOTP,并且如果服务器要在22hr:30m:6s:40ms进行验证,那么totp是否会有所不同?即使我们每个使用3个步长为30秒的步骤,我们也不会错过22hr:30m:2s:33ms停止吗?
I have this questions because, if I were to generate a TOTP at 22hr:30m:2s:33ms and if the server was to verify it at 22hr:30m:6s:40ms, wont the totp be different? Even if we use 3 steps of 30 seconds each, wont we be missing the 22hr:30m:2s:33ms stop?
我想我在这里没有重点.
I think I am missing the main point here.
推荐答案
以下是使用Java进行四舍五入的方法
Here is how it is rounded using Javascript
var time = leftpad(dec2hex(Math.floor(epoch / 30)), 16, '0');
因此,您所要回答的部分是" Math.floor(epoch/30)",这意味着OTP在12:22:30、12:22:37、12:22生成:39 .... 12:22:59完全一样
So what you ask is answered this part "Math.floor(epoch / 30)" , meaning that the OTP generated at 12:22:30, 12:22:37, 12:22:39 .... 12:22:59 is exactly the same
这篇关于TOTP:秒数计数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!