kspearrin / Otp.NET

A .NET implementation of TOTP and HOTP for things like two-factor authentication codes.
https://www.nuget.org/packages/Otp.NET
MIT License
1.08k stars 164 forks source link

Code invalid (not matching Google Auth) #38

Closed andresmurman closed 1 year ago

andresmurman commented 1 year ago

Hi! I have a little problem. The code generated by ComputeTotp is different from the one shown in Google Authenticator.

I generate a base32 key like this (code in VB)

Dim secretKey As Byte() = KeyGeneration.GenerateRandomKey()

Dim base32String As String = Base32Encoding.ToString(secretKey )

I pass this base32String as secret to the QR I generate (I also tried entering the key manually, both generates the same random codes)

Then, when I try to validate the code, the generated code is different from the one in Google. Heres my code:

Dim secretKeyData As Byte() = Base32Encoding.ToBytes(secretKey)
Dim totp As New Totp(secretKeyData)
Dim validCode As String = totp.ComputeTotp()
'validCode is different from the one that appears on Google Authenticator

This is one of the keys that was randomly generated: 4FY2PLSR6WZ5V72YQS5SAE3VRPQRGWLQ

Any clue in what im doing wrong?

Thanks!

andresmurman commented 1 year ago

Well, my PC was 2 minutes ahead. Now everything is working...