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 PATH
This step makes the keytool utility available from the command line.
Open a command prompt and change directory to the directory where you store your keystore
files, KeystoreDir
. Enter the following command:
keytool -genkey -dname "CN=Alice, OU=Engineering, O=Progress, 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 the key are both
placed in a key entry in a newly created keystore,
. Because the specified keystore,
CertName
.jks
, did not exist prior to 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 the 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, as
follows: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, as follows:
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, as follows: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, as follows:CertName
.jks
keytool -import -fileCertName
.chain -keypassCertPassword
-keystoreCertName
.jks -storepassCertPassword