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

Example of generating an asymmetric key and CSR.

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 CSRGenerate {
static String ipHSM = "127.0.0.1";
static String usr_admin = "master";
static String pass_admin = "12345678";
static String keyName = "rsa_key";
static String szDN = "/CN=BANCO DO BRASIL SA P033/OU=SISBACEN-00001/OU=ISPB-00000000/O=ICP-Brasil/L=BRASILIA/S=DF/C=BR";
public static void main(String[] args) throws TacException, IOException {
Dinamo api = new Dinamo();
System.out.println("--> Login HSM");
api.openSession(ipHSM, usr_admin, pass_admin);
System.out.println("--> Create new key");
api.createKey(keyName, TacNDJavaLib.ALG_RSA_2048);
System.out.println("--> Export PKCS#10");
byte[] arq=api.generatePKCS10CSR(keyName, szDN,TacNDJavaLib.P10_CSR_DER);
Files.write(Paths.get("chave.csr"), arq);
System.out.println("--> Delete key");
api.deleteKey(keyName);
System.out.println("--> Logout HSM");
api.closeSession();
System.out.println("The process ended successfully");
}
}