首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OTP Google Acc.兼容

OTP Google Acc.兼容
EN

Stack Overflow用户
提问于 2014-12-24 00:09:14
回答 1查看 424关注 0票数 0

我正在致力于一个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

代码语言:javascript
复制
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位数的值)。

我不太确定要理解的部分是:

代码语言:javascript
复制
 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 

有人能给我一个更详细的解释吗?

谢谢,

EN

回答 1

Stack Overflow用户

发布于 2014-12-24 01:04:58

我的猜测是,您可能会错误地获取offset的值。这句话

哈希的最后一个半字节的

如果你没有正确的比特和字节排序的定义,它是非常模糊的。引用的维基百科页面有许多实现的链接,我认为this Java implementation可以用来检查您的代码:

代码语言:javascript
复制
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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27623964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档