This provides some simple certificate management functionality. Specifically, it allows you to create self-signed X.509 certificates as well as PKCS 10 based certificate signing requests.
Keys for some public key signature algorithms have algorithm parameters, such as DSS/DSA. Some sites' Certificate Authorities adopt fixed algorithm parameters, which speeds up some operations including key generation and signing. At this time, this interface supports initializing with a named group.
Also, note that at this time only signature-capable keys may be acquired through this interface. Diffie-Hellman keys, used for secure key exchange, may be supported later.
PKCS10, X509CertImpl
| Modifier and Type | Field and Description |
|---|---|
| private KeyPairGenerator | |
| private final String | |
| private PrivateKey | |
| private SecureRandom | |
| private PublicKey | |
| private String | |
| private boolean | |
| private PrivateKey | |
| private X500Name |
| Access | Constructor and Description |
|---|---|
| public | CertAndKeyGen(String
type of key, e.g. "RSA", "DSA" keyType, String name of the signature algorithm, e.g. "MD5WithRSA",
"MD2WithRSA", "SHAwithDSA". If set to null, a default
algorithm matching the private key will be chosen after
the first keypair is generated. sigAlg)Creates a CertAndKeyGen object for a particular key type and signature algorithm. |
| public | |
| public | CertAndKeyGen(String
type of key, e.g. "RSA", "DSA", "X25519", "DH", etc. keyType, String name of the signature algorithm, e.g. "SHA384WithRSA",
"SHA256withDSA", etc. If set to null, a default
algorithm matching the private key or signer's private
key will be chosen after the first keypair is generated. sigAlg, String name of the provider providerName, PrivateKey (optional) signer's private key signerPrivateKey, X500Name (optional) signer's subject name signerSubjectName)Creates a CertAndKeyGen object for a particular key type, signature algorithm, and provider. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| private void | |
| public PrivateKey | |
| public X509Key | getPublicKey()
Returns the public key of the generated key pair if it is of type
|
| public PublicKey | |
| public X509Certificate | getSelfCertificate(X500Name
X.500 name of the subject (who is also the issuer) myname, Date the issue time of the certificate firstDate, long how long the certificate should be valid, in seconds validity)Returns a self-signed X.509v3 certificate for the public key. |
| public X509Certificate | |
| public X509Certificate | |
| public void |
| keyGen | back to summary |
|---|---|
| private KeyPairGenerator keyGen | |
| keyType | back to summary |
|---|---|
| private final String keyType | |
| privateKey | back to summary |
|---|---|
| private PrivateKey privateKey | |
| prng | back to summary |
|---|---|
| private SecureRandom prng | |
| publicKey | back to summary |
|---|---|
| private PublicKey publicKey | |
| sigAlg | back to summary |
|---|---|
| private String sigAlg | |
| signerFlag | back to summary |
|---|---|
| private boolean signerFlag | |
| signerPrivateKey | back to summary |
|---|---|
| private PrivateKey signerPrivateKey | |
| signerSubjectName | back to summary |
|---|---|
| private X500Name signerSubjectName | |
| CertAndKeyGen | back to summary |
|---|---|
| public CertAndKeyGen(String keyType, String sigAlg) throws NoSuchAlgorithmException Creates a CertAndKeyGen object for a particular key type and signature algorithm.
| |
| CertAndKeyGen | back to summary |
|---|---|
| public CertAndKeyGen(String keyType, String sigAlg, String providerName) throws NoSuchAlgorithmException, NoSuchProviderException | |
| CertAndKeyGen | back to summary |
|---|---|
| public CertAndKeyGen(String keyType, String sigAlg, String providerName, PrivateKey signerPrivateKey, X500Name signerSubjectName) throws NoSuchAlgorithmException, NoSuchProviderException Creates a CertAndKeyGen object for a particular key type, signature algorithm, and provider. The newly generated cert will be signed by the signer's private key when it is provided.
| |
| generate | back to summary |
|---|---|
| public void generate(String name) | |
| generate | back to summary |
|---|---|
| public void generate(int keyBits) | |
| generateInternal | back to summary |
|---|---|
| private void generateInternal() Generates a random public/private key pair. Note that not all public key algorithms are currently supported for use in X.509 certificates. If the algorithm you specified does not produce X.509 compatible keys, an invalid key exception is thrown.
| |
| getPrivateKey | back to summary |
|---|---|
| public PrivateKey getPrivateKey() Returns the private key of the generated key pair. Be extremely careful when handling private keys. When private keys are not kept secret, they lose their ability to securely authenticate specific entities ... that is a huge security risk! | |
| getPublicKey | back to summary |
|---|---|
| public X509Key getPublicKey() Returns the public key of the generated key pair if it is of type
| |
| getPublicKeyAnyway | back to summary |
|---|---|
| public PublicKey getPublicKeyAnyway() Always returns the public key of the generated key pair. Used by KeyTool only. The publicKey is not necessarily to be an instance of X509Key in some JCA/JCE providers, for example SunPKCS11. | |
| getSelfCertificate | back to summary |
|---|---|
| public X509Certificate getSelfCertificate(X500Name myname, Date firstDate, long validity) throws CertificateException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, NoSuchProviderException Returns a self-signed X.509v3 certificate for the public key. The certificate is immediately valid. No extensions. Such certificates normally are used to identify a "Certificate Authority" (CA). Accordingly, they will not always be accepted by other parties. However, such certificates are also useful when you are bootstrapping your security infrastructure, or deploying system prototypes.
| |
| getSelfCertificate | back to summary |
|---|---|
| public X509Certificate getSelfCertificate(X500Name myname, Date firstDate, long validity, CertificateExtensions ext) throws CertificateException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, NoSuchProviderException | |
| getSelfCertificate | back to summary |
|---|---|
| public X509Certificate getSelfCertificate(X500Name myname, long validity) throws CertificateException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, NoSuchProviderException | |
| setRandom | back to summary |
|---|---|
| public void setRandom(SecureRandom generator) Sets the source of random numbers used when generating keys. If you do not provide one, a system default facility is used. You may wish to provide your own source of random numbers to get a reproducible sequence of keys and signatures, or because you may be able to take advantage of strong sources of randomness/entropy in your environment. | |