【问题标题】:How can you generate OTP with system.security.cryptography that can be authenticated on client?如何使用 system.security.cryptography 生成可以在客户端进行身份验证的 OTP?
【发布时间】:2011-04-11 06:14:47
【问题描述】:

有人知道我在哪里可以找到带有 system.security.cryptography 命名空间的示例代码——或者开发人员可以遵循的说明吗?

目的是为 asp.net 网站添加双重身份验证。在网站上,我想要求用户输入密码(类似于他们从钥匙扣获得密码)。在客户端,我想提供一个生成正确密码的 vb.net windows.forms 程序。

我想在小范围内使用 system.security.cryptography 命名空间来做到这一点。我正在寻找我不想弄乱设备或购买身份验证服务器设备的示例代码。

大多数算法都需要高级数学学位或适用于其他平台,例如 Linux 或 PHP。我正在寻找 .net 等价物。

【问题讨论】:

  • 为什么需要这个?我认为可能会有更好的解决方案,如果您提供更多信息,您可能会获得更好的安全性和解决方案。
  • 向 asp.net 网站添加双重身份验证。在网站上,我想要求用户输入密码(类似于他们从钥匙扣获得密码)。在客户端,我想提供一个生成正确密码的 vb.net windows.forms 程序。我想用 system.security.cryptography 命名空间来做到这一点。正在寻找示例代码。

标签: .net cryptography one-time-password system.security


【解决方案1】:

RFC4226(基于计数器的 OTP)或draft-mraihi-totp-timebased(基于时间的 OTP)的加密部分相对简单:

  1. 根据共享密钥和计数器/时间生成 HMAC
  2. 以安全的方式截断它

通常是用户管理和静态/动态同步使其变得复杂。

这样的事情应该可以工作:

public static int CalculateHotp(byte[] key, byte[] counter)
{
    var hmacsha1 = new HMACSHA1(key);
    byte[] hmac_result = hmacsha1.ComputeHash(counter);
    int offset = hmac_result[19] & 0x0f;
    int bin_code = (hmac_result[offset]  & 0x7f) << 24
                   | (hmac_result[offset+1] & 0xff) << 16
                   | (hmac_result[offset+2] & 0xff) <<  8
                   | (hmac_result[offset+3] & 0xff);
    int hotp = bin_code % 1000000;
    return hotp;
}

【讨论】:

  • 谢谢,但是你如何在 .NET 中使用 system.security.cryptography 做到这一点?
  • pghcpa:看看这个link
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-10
  • 1970-01-01
  • 2022-10-30
  • 2014-08-23
  • 1970-01-01
  • 2015-10-29
  • 2018-07-05
相关资源
最近更新 更多