c# - OtpSharp 不与谷歌身份验证器一起使用
问题描述
我一直在尝试在我正在开发的应用程序中使用 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 密钥,而是需要一个 Base32 字符串作为输入,我假设它后来被解码为字节数组并由库使用。
因此,我向 OtpSharp 提供了任意 unicode 字符串的字节字符串表示形式,并使用在线网站将 unicode 字符串解码为 base32 字符串,并在 Google Authenticator 中使用了 base32 字符串。
简单来说,Otpsharp 需要一个字节数组来初始化一个 totp 对象,而 pyotp 需要你提供一个 base32 字符串。
推荐阅读
- java - 在 JsonArray 中插入新元素
- javascript - 将表单数据发送到 firebase 函数
- javascript - 用户滚动时将 div 粘贴在屏幕上
- r - 根据不同行中的值替换某些行中的值
- android - 为 APK 触发时,“keytool”命令中缺少 MD5
- visual-studio - Visual Studio 2013 更新 5:无法创建无人参与安装
- mysql - 平日最近 3 天记录
- python - 在 Tensorflow 1.13 和 Keras 中重塑 LSTM 网络的输入
- git - Git拒绝访问 - 权限被拒绝(公钥)
- android - 如何在整个主题中更改 AppBarLayout 的样式?