目前,我正在尝试实现一个使用RFC4226 - HOTP:一种基于HMAC的一次性密码算法作为基础的示例。
我取了代码样本,并补充道:
public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException {
// Seed
String secret = "12345678901234567890";
byte[] secretBytes = secret.getBytes();
int counter;
for (counter = 0; counter < 9; counter++) {
String strGeneratedToken = OneTimePasswordAlgorithm.generateOTP(secretBytes, counter, 6, false, 0);
System.out.println(strGeneratedToken);
}
}我得到的只是:
755224 717529 868666 023335 179456 490877 910469 467724 952310
第一个是可以的,但是下一个(counter=1)按照RFC (755224 287082 359152 969429 338314 254676 287922 162583 399871 520489)。
我已经把我的代码上传到了GitHub https://github.com/n0l0cale/hotp --也许有人能看到这个问题。
这个实现似乎有相同的问题:.htm
我不会介意,但是当我为我的Java应用程序和我的谷歌认证应用程序尝试相同的秘密时,我也会得到其他代码。"12345678901234567890“当然不是秘密的,但我试过用同样的密码,谷歌身份验证应用程序似乎启动了他们的计数器0,但增加了他们的计数器第一次使用.
发布于 2018-06-19 14:09:53
truncationOffset似乎被要求设置为16.
字符串strGeneratedToken =strGeneratedToken计数器,6,false,16);
public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException {
// Seed
String secret = "12345678901234567890";
byte[] secretBytes = secret.getBytes();
int counter;
for (counter = 0; counter < 9; counter++) {
String strGeneratedToken = OneTimePasswordAlgorithm.generateOTP(secretBytes, counter, 6, false, 16);
System.out.println(strGeneratedToken);
}
}755224 287082 359152 969429 338314 254676 287922 162583 399871 520489
https://stackoverflow.com/questions/50923576
复制相似问题