API Java
HSM Dinamo
Cargando...
Buscando...
No se han encontrado entradas
ImportExportP8.java

Ejemplo de importación y exportación de una clave en formato PKCS#8.

Véase la nota sobre ejemplos.
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();
}
}