Interface CertificateBuilder
public interface CertificateBuilder
The interface for the creation of certificates.
The default type of certificate is an X509 certificate, however, there are a number of considerations when using this interface to generate self-signed certificates.
- The Certificate is valid from "now" until 12months from now.
- The unique serial id for the certificate is a random number between 0 and 10000
- Subject unique ID or Issuer unique id is not set
- No V3 extensions are added.
- The base version of the certificate is 1
Example Use
CertificateParameter cp = new CertificateParameter();
X500NameBuilder subject = new X500NameBuilder();
subject.addRDN(X509ObjectIdentifiers.countryName, "GB");
subject.addRDN(X509ObjectIdentifiers.stateOrProvinceName, "Middlesex");
subject.addRDN(X509ObjectIdentifiers.localityName, "Uxbridge");
subject.addRDN(X509ObjectIdentifiers.organization, "Adaptris");
subject.addRDN(X509ObjectIdentifiers.organizationalUnitName, "Development");
subject.addRDN(X509ObjectIdentifiers.commonName, "My Name");
subject.addRDN(PKCSObjectIdentifiers.pkcs_9_at_emailAddress, "myname@mycompany.com");
cp.setSignatureAlgorithm("Md5WithRSAencryption");
cp.setKeyAlgorithm("RSA", 2048);
cp.setSubjectInfo(subject.build());
// Now actually create the certificate
CertificateBuilder cm = CertificateBuilderFactory.getInstance().createBuilder();
cm.setCertificateParameters(cp);
Certificate cert = cm.createSelfSignedCertificate();
// Just print out some information.
System.out.println(cert.toString());
System.out.println(cm.createCertificateRequest());
System.out.println(cm.getPublicKey());
System.out.println(cm.getPrivateKey());
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionCreate a self-signed certificate, and return it as aCertificate
object.void
Create a self signed certificate, and write it to the supplied oututStream.Return the private key associated with the recently created certificate.Return the public key associated with the recently created certificate.void
reset()
Reset the internal state, ready to create a new certificate.void
Set the certificate parameters for this maker object.
-
Method Details
-
setCertificateParameters
Set the certificate parameters for this maker object.The certificate parameters determine the x.500 information that goes into the certificate
- Parameters:
cm
- the Certifcate Parameters- See Also:
-
getPrivateKey
PrivateKey getPrivateKey()Return the private key associated with the recently created certificate.- Returns:
- the private key, null if no certificate has been created
-
getPublicKey
PublicKey getPublicKey()Return the public key associated with the recently created certificate.- Returns:
- the public key, null if no certificate has been created
-
reset
void reset()Reset the internal state, ready to create a new certificate.It must be invoked if attempting to create more one certificate using the same object. It does not necessarily have to be called if this is the first time creating a certificate
-
createSelfSignedCertificate
Create a self signed certificate, and write it to the supplied oututStream.The default implementation writes out the certificate as a DER encoded ASN.1 data structure
- Parameters:
out
- the OutputStream to write to- Throws:
AdaptrisSecurityException
- if any error occurs- See Also:
-
createSelfSignedCertificate
Create a self-signed certificate, and return it as aCertificate
object.- Returns:
- the created certificate
- Throws:
AdaptrisSecurityException
- if any error occurs- See Also:
-