我正在使用https://www.nuget.org/packages/Otp.NET库来生成和验证OTP。我想使用TOTP算法。生成的OTP需要有效5分钟。库建议使用var totp = new Totp(secretKey, step: 300);
这样。但是OTP在5分钟前失效了
完整代码
public static void GenarateTOTP()
{
var bytes = Base32Encoding.ToBytes("JBSWY3DPEHPK3PXP");
var totp = new Totp(bytes, step: 300);
var result = totp.ComputeTotp(DateTime.UtcNow);
Console.WriteLine(result);
var input = Console.ReadLine();
long timeStepMatched;
bool verify = totp.VerifyTotp(input, out timeStepMatched, window: null);
Console.WriteLine("{0}-:{1}", "timeStepMatched",timeStepMatched);
Console.WriteLine("{0}-:{1}", "Remaining seconds", totp.RemainingSeconds());
Console.WriteLine("{0}-:{1}", "verify", verify);
}