To create and sign a certificate in a Java keystore (JKS), , perform the following substeps:CertName.jks
If you have not already done so, add the Java bin
directory to your path:
Windows
> set PATH=JAVA_HOME\bin;%PATH%UNIX
% PATH=JAVA_HOME/bin:$PATH; export PATHThis step makes the keytool utility available from the command line.
Open a command prompt and change directory to KeystoreDir.
Enter the following command:
keytool -genkey -dname "CN=Alice, OU=Engineering, O=IONA Technologies PLC, ST=Co. Dublin, C=IE" -validity 365 -aliasCertAlias-keypassCertPassword-keystoreCertName.jks -storepassCertPassword
This keytool command, invoked with the -genkey option, generates an X.509 certificate and a matching
private key. The certificate and key are both placed in a key entry in a
newly created keystore, . Because the specified keystore, CertName.jks, did not exist before issuing the command, keytool implicitly creates a new keystore.CertName.jks
The -dname and -validity flags define the contents of the newly created X.509 certificate,
specifying the subject DN and days before expiration respectively. For more details about DN
format, see Appendix A .
Some parts of the subject DN must match the values in the CA certificate (specified in the
CA Policy section of the openssl.cnf file). The default
openssl.cnf file requires the following entries to match:
Country Name (C)
State or Province Name (ST)
Organization Name (O)
![]() | Note |
|---|---|
If you do not observe the constraints, the OpenSSL CA will refuse to sign the certificate (see Sign the CSR ). |
Create a new certificate
signing request (CSR) for the certificate:CertName.jks
keytool -certreq -aliasCertAlias-fileCertName_csr.pem -keypassCertPassword-keystoreCertName.jks -storepassCertPassword
This command exports a CSR to the file, .CertName_csr.pem
Sign the CSR using your CA:
openssl ca -configX509CA/openssl.cnf -days 365 -inCertName_csr.pem -outCertName.pem
To sign the certificate successfully, you must enter the CA private key pass phrase—see Set Up Your Own CA .
![]() | Note |
|---|---|
If you want to sign the CSR using a CA certificate other than the
default CA, use the |
Convert the signed certificate, , to PEM only format:CertName.pem
openssl x509 -inCertName.pem -outCertName.pem -outform PEM
Concatenate the CA certificate file and certificate file, as follows:CertName.pem
Windows
copyCertName.pem +X509CA\ca\new_ca.pemCertName.chain
UNIX
catCertName.pemX509CA/ca/new_ca.pem>CertName.chain
Update the keystore, , by importing the full certificate chain for the certificate:CertName.jks
keytool -import -fileCertName.chain -keypassCertPassword-keystoreCertName.jks -storepassCertPassword