question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated codes do not match Google Authenticator results

See original GitHub issue

I am using this code:

string secret = "KREQPD7NXSGO3T3B";
while (true)
{
    byte[] secretBytes = new Base32Encoder().Decode(secret);
    OtpNet.Totp totp = new OtpNet.Totp(secretBytes);
    string twoFactorCode = totp.ComputeTotp();

    Console.WriteLine("Two factor code: " + twoFactorCode);

    System.Threading.Thread.Sleep(2000);
}

Now if you take that same string (for secret) and put it in to Google Authenticator manually, you will notice that this code generates different keys. On the otherhand, if I use a different value for secret (eg “uhj34qsyuwftzji4qq6k3c3wnstdb57m”) then both the values generated by OtpNet and Google Authenticator will match.

What am I doing wrong?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
shyboylpfcommented, Jun 21, 2018

I just got it. The way to get bytes[] is wrong. I need to use var secretKey = Base32Encoding.ToBytes(OtpSecretKey); Then OtpNet and Google Authenticator will match.

0reactions
shyboylpfcommented, Jul 4, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Generated codes do not match with PyOTP sample
Go to the main menu on the Google Authenticator app Tap More and then Settings. Tap Time correction for codes Tap Sync now...
Read more >
Fix common issues with 2-Step Verification
My Google Authenticator codes don't work · On your Android device, go to the main menu of the Google Authenticator app. · Tap...
Read more >
[RESOLVED] PHP code not matching Google Authenticator ...
Hello, I'm trying to get some PHP code matching what the Google Authenticator on my phone outputs. I'm using HOTP (Once I get...
Read more >
How to Fix Google Authenticator Codes That Have ...
1. Sync the App's Time. Mobile users might find that their Google Authenticator codes aren't working when logging into their accounts. And ...
Read more >
Authenticator App codes do not work—does not allow any ...
I have tried using Authenticator App codes generated by Authy (iOS app), which do no work. I have tried accessing codes from other...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found