0

我正在執行OTP Google Acc。兼容。OTP Google Acc。兼容

到目前爲止,我一直在使用

-RFC2104(http://www.ietf.org/rfc/rfc2104.txt),

-RFC4226(http://www.ietf.org/rfc/rfc4226.txt),

-RFC6238(https://tools.ietf.org/html/rfc6238),並按照這個模式:

[僞代碼時間OTP](http://en.wikipedia.org/wiki/Google_Authenticator#Pseudocode_for_Time_OTP

​​

直到「hash:= HMAC-SHA1(key,message)」一切正常。我通過其他HMAC-SHA1轉換器檢查了多次結果。 (嗯,我認爲是)。

但是,然後,我認爲必須出問題...因爲顯然我沒有得到與我的谷歌驗證器應用程序(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 

可能有人給我這個更詳細的解釋?

感謝,

回答

0

我的猜測是,你可以採取的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;