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

Example of export and import in TR-31 format.

See Note on examples.
package doxy.examples;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class ExportImportTR31 {
public static void main(String[] args) throws TacException {
Dinamo api = new Dinamo();
api.openSession("127.0.0.1", "master", "12345678", false);
String kbpk = "kbpk"; //Name of the key used to derive the encryption and authentication keys
String key = "key"; //Name of the key to be exported
api.createKey(key, TacNDJavaLib.ALG_AES_128, true);
api.createKey(kbpk, TacNDJavaLib.ALG_AES_256, true);
/*
* Exports a key in TR-31 format.
*/
byte[] keyBlock = api.exportTR31(kbpk, key, TacNDJavaLib.EFT_ME_TR31_EXP_USAGE_AUTO,
TacNDJavaLib.EFT_ME_TR31_EXP_MODE_AUTO,
TacNDJavaLib.EFT_ME_TR31_EXP_AUTO);
System.out.println("Key successfully exported.");
/*
* Import a key in TR-31 format.
*/
String impKey = "impKey"; //Name of imported key
api.importTR31(kbpk, impKey, TacNDJavaLib.EXPORTABLE_KEY, keyBlock);
System.out.println("Key imported successfully.");
/*
* Remove the test keys.
*/
api.deleteKey(key);
api.deleteKey(kbpk);
api.deleteKey(impKey);
api.closeSession();
}
}