Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HOTP-正确使用RFC样本_Java - Fatal编程技术网

Java HOTP-正确使用RFC样本

Java HOTP-正确使用RFC样本,java,Java,我目前正在尝试实现一个使用作为基础的示例 我获取了代码示例并添加了: public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException { // Seed String secret = "12345678901234567890"; byte[] secretBytes = secret.getBytes(); int counter;

我目前正在尝试实现一个使用作为基础的示例

我获取了代码示例并添加了:

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);
    }
}
publicstaticvoidmain(字符串[]args)抛出InvalidKeyException、NoSuchAlgorithmException{
//种子
String secret=“123456789001234567890”;
字节[]secretBytes=secret.getBytes();
整数计数器;
用于(计数器=0;计数器<9;计数器++){
String strGeneratedToken=OneTimePasswordAlgorithm.generateOTP(secretBytes,counter,6,false,0);
System.out.println(strGeneratedToken);
}
}
我得到的只是:

755224 717529 868666 023335 179456 490877 910469 467724 952310

第一个可以,但下一个(计数器=1)符合RFC(755224287082 359152 969429 338314 254676 287922 162583 399871 520489)

我已经将我的代码上传到GitHub——也许有人能够看到这个问题

此实施似乎存在相同的问题:


我决不会这样做,但是当我为我的Java应用程序和我的应用程序尝试同样的秘密时,我也会得到其他代码。“123456789001234567890”当然不能作为秘密使用,但我尝试过使用相同的密码短语,Google Authenticator应用程序似乎将计数器的起始值设置为0,但在首次使用时会增加计数器…

truncationOffset似乎需要设置为16

String strGeneratedToken=OneTimePasswordAlgorithm.generateOTP(secretBytes,counter,6,false,16

publicstaticvoidmain(字符串[]args)抛出InvalidKeyException、NoSuchAlgorithmException{
//种子
String secret=“123456789001234567890”;
字节[]secretBytes=secret.getBytes();
整数计数器;
用于(计数器=0;计数器<9;计数器++){
String strGeneratedToken=OneTimePasswordAlgorithm.generateTP(secretBytes,counter,6,false,16);
System.out.println(strGeneratedToken);
}
}
755224 287082 359152 969429 338314 254676 287922 162583 399871 520489

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);
    }
}