public class RootCertificateGenerator extends Object implements CertificateAndKeySource
CertificateAndKeySource that dynamically generates a CA root certificate and private key. The certificate
and key will only be generated once; all subsequent calls to load() will return the same materials. To save
the generated certificate and/or private key for installation in a browser or other client, use one of the encode
or save methods:
| Modifier and Type | Class and Description |
|---|---|
static class |
RootCertificateGenerator.Builder
A Builder for
RootCertificateGenerators. |
| Constructor and Description |
|---|
RootCertificateGenerator(CertificateInfo rootCertificateInfo,
String messageDigest,
KeyGenerator keyGenerator,
SecurityProviderTool securityProviderTool) |
| Modifier and Type | Method and Description |
|---|---|
static RootCertificateGenerator.Builder |
builder()
Convenience method to return a new
RootCertificateGenerator.Builder instance. |
String |
encodePrivateKeyAsPem(String privateKeyPassword)
Returns the generated private key as a PEM-encoded String, encrypted using the specified password and the
DEFAULT_PEM_ENCRYPTION_ALGORITHM. |
String |
encodeRootCertificateAsPem()
Returns the generated root certificate as a PEM-encoded String.
|
CertificateAndKey |
load()
Loads a certificate and its corresponding private key.
|
void |
savePrivateKeyAsPemFile(File file,
String passwordForPrivateKey)
Saves the private key as PEM-encoded data to a file, using the specified password to encrypt the private key and
the
DEFAULT_PEM_ENCRYPTION_ALGORITHM. |
void |
saveRootCertificateAndKey(String keyStoreType,
File file,
String privateKeyAlias,
String password)
Saves the generated certificate and private key as a file, using the specified password to protect the key store.
|
void |
saveRootCertificateAsPemFile(File file)
Saves the root certificate as PEM-encoded data to the specified file.
|
public RootCertificateGenerator(CertificateInfo rootCertificateInfo, String messageDigest, KeyGenerator keyGenerator, SecurityProviderTool securityProviderTool)
public CertificateAndKey load()
CertificateAndKeySourceCertificateAndKey instance).load in interface CertificateAndKeySourcepublic String encodeRootCertificateAsPem()
public String encodePrivateKeyAsPem(String privateKeyPassword)
DEFAULT_PEM_ENCRYPTION_ALGORITHM.privateKeyPassword - password to use to encrypt the private keypublic void saveRootCertificateAsPemFile(File file)
public void savePrivateKeyAsPemFile(File file, String passwordForPrivateKey)
DEFAULT_PEM_ENCRYPTION_ALGORITHM. If the password is null, the private key will be stored unencrypted.
In general, private keys should not be stored unencrypted.file - file to save the private key topasswordForPrivateKey - password to protect the private keypublic void saveRootCertificateAndKey(String keyStoreType, File file, String privateKeyAlias, String password)
keyStoreType - the KeyStore type, such as PKCS12 or JKSfile - file to export the root certificate and private key toprivateKeyAlias - alias for the private key in the KeyStorepassword - password for the private key and the KeyStorepublic static RootCertificateGenerator.Builder builder()
RootCertificateGenerator.Builder instance.Copyright © 2016. All Rights Reserved.