2
RFC的测试值规定:这是RFC 4226错误吗?
Appendix D - HOTP Algorithm: Test Values
The following test data uses the ASCII string
"123456789" for the secret:
Secret = 0x3132333435363738393031323334353637383930
Table 1 details for each count, the intermediate HMAC value.
Count Hexadecimal HMAC-SHA-1(secret, count)
0 cc93cf18508d94934c64b65d8ba7667fb7cde4b0
1 75a48a19d4cbe100644e8ac1397eea747a2d33ab
所以,如果我试图让HMAC 0在Ruby中,我得到:
[20] pry(AuthyOTP)> secret_key = "123456789"
=> "123456789"
[22] pry(AuthyOTP)> OpenSSL::HMAC.hexdigest(digest, secret_key, "0")
=> "32a67f374525d32d0ce13e3db42b5b4a3f370cce"
我有望获得cc93cf18508d94934c64b65d8ba7667fb7cde4b0
所以我用java写了一个实现,并且我得到了相同的结果:
Calculation OTP for movingFactor = 0
2. Calculate Hash =
32a67f374525d32d0ce13e3db42b5b4a3f370cce
那么秘密是“123456789”时,“0”的十六进制SHA1-HMAC是什么?
你是对的......虽然这只是混乱。特别是因为其他语言的HMAC功能对字符串操作,而不是字节操作。 – daniel 2012-02-26 21:50:43
作为Java程序员,我不在乎其他语言是否不理解字符串和字节之间的差异。这些算法都是为字节定义的,明确执行编码要好得多 - 因为还没有定义标准编码。 – 2012-02-27 02:05:43
是的。我从来没有理解像PHP这样的语言如何为_everything_使用字符串 – SLaks 2012-02-27 03:44:09