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

Example of retrieving the TLS certificate from the HSM without an authenticated session, in DER and PEM formats.

See Note on examples.
package doxy.examples;
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 GetHSMTLSCert {
public static void main(String[] args) {
String ip = "127.0.0.1";
int port = TacNDJavaLib.DEFAULT_PORT;
try {
// Recupera o certificado TLS do HSM no formato PEM (nenhuma sessão necessária).
byte[] pemCert = Dinamo.getHSMTLSCert(ip, port, TacNDJavaLib.CERT_OUT_PEM);
System.out.println("HSM TLS certificate (PEM):");
System.out.println(new String(pemCert));
// Salva o certificado PEM em arquivo para uso posterior com openSessionCert().
Files.write(Paths.get("hsm_cert.pem"), pemCert);
System.out.println("Saved to hsm_cert.pem");
// Também recupera o formato DER para incorporação ou comparação.
byte[] derCert = Dinamo.getHSMTLSCert(ip, port, TacNDJavaLib.CERT_OUT_DER);
System.out.println("DER certificate length: " + derCert.length + " bytes");
} catch (TacException e) {
e.printStackTrace();
} catch (Exception e) {
System.err.println("I/O error: " + e.getMessage());
}
}
}