c# - OtpSharp 无法与 google 身份验证器配合使用

标签 c# python one-time-password google-authenticator

我一直在尝试在我正在开发的应用程序中将 OtpSharp 与 Google Authenticator 一起使用。但是,我不明白为什么 OtpSharp 生成的代码与 Google Authenticator 的代码不匹配。我什至尝试根据我的本地操作系统纠正输入到 OtpSharp 的时间,但没有任何运气。另一方面,Python 的 pyotp 库无需任何特殊努力即可正常工作。 这是我正在使用的代码:

var bSharedKey = System.Text.Encoding.Unicode.GetBytes("TESTTESTTESTTEST");
//var correction = new TimeCorrection(DateTime.UtcNow.ToLocalTime());
//var totp = new Totp(bSharedKey, timeCorrection: correction);
var totp = new Totp(bSharedKey);
var realOtp = totp.ComputeTotp();
long timestep = 0;
var OTPmatch = totp.VerifyTotp(passwords[1], out timestep);

最佳答案

问题是,不是向 pyotp 库(以及 Google Authenticator)提供任意 unicode key ,而是需要 Base32 字符串作为输入,我假设该字符串后来被解码为字节数组并由图书馆。

因此,我向 OtpSharp 提供了任意 unicode 字符串的字节字符串表示形式,并使用在线网站将 unicode 字符串解码为 base32 字符串,并在 Google Authenticator 中使用了 base32 字符串。

简单来说,Otpsharp 需要一个字节数组来初始化 totp 对象,而 pyotp 需要您为其提供一个 base32 字符串。

关于c# - OtpSharp 无法与 google 身份验证器配合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52705347/

相关文章:

c# - 是否有与 m_nCmdShow 等效的 c#?

c# - NLog 异步目标数据库连接异常 - 如何获取它们?

c# - 如何处理需要不同版本程序集的两个库?

java - 安卓 : How to verify email address using OTP

Python Django DRF API 一次性 session / token /通行证身份验证,无需用户名/密码

android - Firebase 不发送 OTP

c# - .NET 权限异常中的网络数据包嗅探

python - 属性错误 : QDialog object has no attribute setCentralWidget

python - 使用 cx_Oracle 时打印列名的更好方法

python - hadoop distcp 使用 subprocess.Popen