Example of 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 ExportP8 {
static String ip = "127.0.0.1";
static String user = "master";
static String password = "12345678";
static String keyName = "tkey";
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, "");
System.out.println("--> Delete key");
api.deleteKey(keyName);
Files.write(Paths.get("chave.pkcs8"), pkcs8);
api.closeSession();
}
}