Example of generating an asymmetric key and extracting the public part.
- See Note on examples.
package doxy.examples;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
import java.util.Base64;
import com.dinamonetworks.Dinamo;
public class ExportPublicKey {
static String ipHSM = "127.0.0.1";
static String usr_admin = "master";
static String pass_admin = "12345678";
static String keyName = "rsa_key";
public static void main(String[] args) throws TacException {
Dinamo api = new Dinamo();
System.out.println("--> Login HSM and create RSA KEY with NONEXPORTABLE_KEY param");
api.openSession(ipHSM, usr_admin, pass_admin);
System.out.println("--> Create key");
api.createKey(keyName, TacNDJavaLib.ALG_RSA_2048, TacNDJavaLib.NONEXPORTABLE_KEY);
System.out.println("--> Export a public key correspondent in DER format");
byte[] publicKey = api.exportKey(keyName, TacNDJavaLib.PUBLICKEY_BLOB);
System.out.println("--> Delete key");
api.deleteKey(keyName);
System.out.println("Result--> " + new String(Base64.getEncoder().encode(publicKey)));
api.closeSession();
System.out.println("The process ended sucessfully");
}
}