- Java JDK 8
- Maven ver.3
Execute follow command,
> mvn package
then myapp-1.0-SNAPSHOT-jar-with-dependencies.jar
will be created in targets
folder.
Execute follow command,
> java -jar target\myapp-1.0-SNAPSHOT-jar-with-dependencies.jar
then you can get OTP code in console.
NOTICE: secret key for OTP is hard coded in .java source file, because this is demonstration code.
The secret key comes from this sample code.
Powered by aerogear-otp-java
.
All of the java source code of this sample is this:
package com.myapp;
import org.jboss.aerogear.security.otp.Totp;
public class App
{
public static void main( String[] args )
{
// Sample secret key: see http://j.mp/2mOovSV
String secretKey = "6jm7n6xwitpjooh7ihewyyzeux7aqmw2";
Totp totp = new Totp(secretKey);
System.out.println(totp.now());
}
}