-
The following code as is from test ExampleApp.java returns error:
package simple;
import javax.crypto.KeyGenerator;
import com.eatthepath.otp.TimeBasedOneTimePasswordGenerator;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
public class ExampleApp {
public static void main(final String[] args) throws NoSuchAlgorithmException, InvalidKeyException {
final TimeBasedOneTimePasswordGenerator totp = new TimeBasedOneTimePasswordGenerator();
final Key key;
{
final KeyGenerator keyGenerator = KeyGenerator.getInstance(totp.getAlgorithm());
// Key length should match the length of the HMAC output (160 bits for SHA-1, 256 bits
// for SHA-256, and 512 bits for SHA-512).
keyGenerator.init(160);
key = keyGenerator.generateKey();
}
final Instant now = Instant.now();
final Instant later = now.plus(totp.getTimeStep());
System.out.println("Current password: " + totp.generateOneTimePasswordString(key, now));
System.out.println("Future password: " + totp.generateOneTimePasswordString(key, later));
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Running on Java 1.8.0 u281 |
Beta Was this translation helpful? Give feedback.
-
ok, found the issue! |
Beta Was this translation helpful? Give feedback.
-
Folks, it sounds like there's a legit problem here. Somebody else has already opened an issue, so let's move the discussion to #27. |
Beta Was this translation helpful? Give feedback.
Folks, it sounds like there's a legit problem here. Somebody else has already opened an issue, so let's move the discussion to #27.