我正在致力于一个OTP Google Acc的实现。兼容。
到目前为止,我一直在使用
-RFC2104(http://www.ietf.org/rfc/rfc2104.txt),
-RFC4226(http://www.ietf.org/rfc/rfc4226.txt),
-RFC6238(https://www.rfc-editor.org/rfc/rfc6238),并遵循此模式:
Pseudo code Time OTP
function GoogleAuthenticatorCode(string secret)
key := base32decode(secret)
message := floor(current Unix time / 30)
hash := HMAC-SHA1(key, message)
offset := value of last nibble of hash
truncatedHash := hash[offset..offset+3] //4 bytes starting at the offset
Set the first bit of truncatedHash to zero //remove the most significant bit
code := truncatedHash mod 1000000
pad code with 0 until length of code is 6
return code 直到“hash := HMAC-SHA1(key,message)”一切正常。我通过其他HMAC-SHA1转换器多次检查结果。(嗯,我想是的)。
但是,我想一定是出了什么问题。因为很明显,我没有得到与我的google-authenticator应用程序(android)相同的代码。(至少它仍然是一个6位数的值)。
我不太确定要理解的部分是:
offset := value of last nibble of hash
truncatedHash := hash[offset..offset+3] //4 bytes starting at the offset
Set the first bit of truncatedHash to zero //remove the most significant bit 有人能给我一个更详细的解释吗?
谢谢,
发布于 2014-12-24 01:04:58
我的猜测是,您可能会错误地获取offset的值。这句话
哈希的最后一个半字节的
值
如果你没有正确的比特和字节排序的定义,它是非常模糊的。引用的维基百科页面有许多实现的链接,我认为this Java implementation可以用来检查您的代码:
byte[] hash = ...
// Dynamically truncate the hash
// OffsetBits are the low order bits of the last byte of the hash
int offset = hash[hash.length - 1] & 0xF;https://stackoverflow.com/questions/27623964
复制相似问题