Java API
HSM Dinamo
Loading...
Looking for...
No entries found
IssueTOTPBlob2.java

Example of generating, verifying and re-synchronizing a TOTP blob OATH using the HSM. With seed generated outside the HSM.

See Note on examples.
package doxy.examples;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class IssueTOTPBlob2 {
private static String strAddr = "127.0.0.1";
private static String strUsrId = "master";
private static String strPwd = "12345678";
private static String masterKeyName = "master_key";
public static void main(String[] args) throws TacException {
Dinamo api = new Dinamo();
System.out.println("--> Login HSM");
api.openSession(strAddr, strUsrId, strPwd);
System.out.println("--> Create a master key");
api.createKey(masterKeyName, TacNDJavaLib.ALG_AES_256, TacNDJavaLib.NONEXPORTABLE_KEY);
byte[] totpSeed = { (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01,
(byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01,
(byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01,
(byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01};
byte[] totpImpBlob = api.importOATHTotpBlob(masterKeyName,
totpSeed);
//This call simulates the client application
String nextOtp = api.getNextOATHOTP(masterKeyName,
TacNDJavaLib.ISSUE_OATH_MIN_OTP_LEN,
totpImpBlob);
System.out.println("--> check OTP value for know seed and sequence");
totpImpBlob = api.checkOATHBlobOTP(masterKeyName, nextOtp, totpImpBlob);
System.out.println("--> Delete the master key");
api.deleteKey(masterKeyName);
api.closeSession();
System.out.println("The process ended sucessfully");
}
}