public class X509CertificateGenerator extends Object
Certificates stored in the keystore can be protected with an additional optional password. This is recommended for root certificates and intermediate certificates.
The DEFAULT_KEY_ALGORITHM is "RSA", the DEFAULT_SIGNATURE_ALGORITHM is "SHA256withRSA". Both can be changed by properties.
The service is based on the BouncyCastle library v 1.67
CAService| Constructor and Description |
|---|
X509CertificateGenerator() |
| Modifier and Type | Method and Description |
|---|---|
void |
exportKeyPairToKeystore(Certificate[] certChain,
PrivateKey privKey,
String password,
String alias,
KeyStore keyStore,
String fileName,
String storePass)
This method stores the certificate into the given keystore.
|
KeyPair |
generateKeyPair()
Generates a new keyPair.
|
X509Certificate |
generateRootCertificate(KeyPair rootKeyPair,
String cn)
This method generates a self signed root certificate.
|
X509Certificate[] |
generateSignedCertificate(X509Certificate rootCert,
PrivateKey rootPrivateKey,
KeyPair issuedCertKeyPair,
String cn,
String o,
List<String> ou,
String city,
String state,
String country)
This method generates a new X509Certificate and signs the certificate from a
given root/intermediate certificate by generating a CSR (Certificate Signing
Request).
|
String |
getKeyAlgorithm() |
String |
getSignatureAlgorithm() |
void |
setKeyAlgorithm(String keyAlgorithm) |
void |
setSignatureAlgorithm(String signatureAlgorithm) |
void |
writeCertToFileBase64Encoded(Certificate certificate,
String fileName)
This method writes a given certificate into a file.
|
public X509CertificateGenerator()
throws KeyStoreException,
UnrecoverableKeyException,
NoSuchAlgorithmException,
NoSuchProviderException
public String getKeyAlgorithm()
public void setKeyAlgorithm(String keyAlgorithm)
public String getSignatureAlgorithm()
public void setSignatureAlgorithm(String signatureAlgorithm)
public X509Certificate generateRootCertificate(KeyPair rootKeyPair, String cn) throws org.bouncycastle.operator.OperatorCreationException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException
The method returns the root certificate.
rootKeyPair - - key pair used to generated the certificatecn - - common name of the root certificateorg.bouncycastle.operator.OperatorCreationExceptionNoSuchAlgorithmExceptionIOExceptionCertificateExceptionKeyStoreExceptionExceptionpublic X509Certificate[] generateSignedCertificate(X509Certificate rootCert, PrivateKey rootPrivateKey, KeyPair issuedCertKeyPair, String cn, String o, List<String> ou, String city, String state, String country) throws NoSuchAlgorithmException, org.bouncycastle.operator.OperatorCreationException, org.bouncycastle.cert.CertIOException, CertificateException, InvalidKeyException, NoSuchProviderException, SignatureException
The method returns a certificate chain containing the issuer certificate and the root certificate. A certificate chain can be stored in a keyStore.
NoSuchAlgorithmExceptionorg.bouncycastle.operator.OperatorCreationExceptionorg.bouncycastle.cert.CertIOExceptionCertificateExceptionSignatureExceptionNoSuchProviderExceptionInvalidKeyExceptionhttps://gist.github.com/vivekkr12/c74f7ee08593a8c606ed96f4b62a208apublic KeyPair generateKeyPair()
public void exportKeyPairToKeystore(Certificate[] certChain, PrivateKey privKey, String password, String alias, KeyStore keyStore, String fileName, String storePass) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException
certificate - - the certificate to be storedprivKey - - the associated private keypassword - - optional password to protect the entry, can be nullalias - - alias name to store the entryfileName - - filename of the keystore location.storePass - - password for keystoreKeyStoreExceptionIOExceptionCertificateExceptionNoSuchAlgorithmExceptionExceptionpublic void writeCertToFileBase64Encoded(Certificate certificate, String fileName) throws Exception
certificate - fileName - ExceptionCopyright © 2016–2021 Imixs Software Solutions GmbH. All rights reserved.