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

Example of importing and exporting a key in PKCS#8 format.

See Note on examples.
package doxy.examples;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class ImportExportP8 {
static String ip = "127.0.0.1";
static String user = "master";
static String password = "12345678";
static String keyName = "tkey";
static String keyNameImp = "tkeyimp";
public static void main(String[] args) throws TacException, IOException {
Dinamo api = new Dinamo();
api.openSession(ip, user, password);
System.out.println("--> Create key");
api.createKey(keyName, TacNDJavaLib.ALG_RSA_2048);
System.out.println("--> Export key in PKCS8 format");
byte[] pkcs8 = api.PKCS8ExportKey(keyName, "");
Files.write(Paths.get("chave.pkcs8"), pkcs8);
System.out.println("--> Import key in PKCS8 format");
api.PKCS8ImportKey(keyNameImp, "", TacNDJavaLib.ALG_RSA_2048, pkcs8, false);
System.out.println("--> Delete key");
api.deleteKey(keyName);
api.deleteKey(keyNameImp);
api.closeSession();
}
}