Top Description Fields Constructors Methods
org.bouncycastle.cert

public Class X509v3CertificateBuilder

extends Object
Class Inheritance
Known Direct Subclasses
org.bouncycastle.cert.bc.BcX509v3CertificateBuilder, org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder
Imports
java.io.IOException, .OutputStream, java.math.BigInteger, java.util.Date, .Enumeration, .Locale, org.bouncycastle.asn1.ASN1Encodable, .ASN1EncodableVector, .ASN1Encoding, .ASN1Integer, .ASN1Object, .ASN1ObjectIdentifier, .DERBitString, .DERNull, .DEROctetString, .DERSequence, org.bouncycastle.asn1.x500.X500Name, org.bouncycastle.asn1.x509.AlgorithmIdentifier, .Certificate, .DeltaCertificateDescriptor, .Extension, .Extensions, .ExtensionsGenerator, .SubjectPublicKeyInfo, .TBSCertificate, .Time, .V3TBSCertificateGenerator, org.bouncycastle.operator.ContentSigner, org.bouncycastle.util.Exceptions

class to produce an X.509 Version 3 certificate.

Field Summary

Modifier and TypeField and Description
private ExtensionsGenerator
private V3TBSCertificateGenerator

Constructor Summary

AccessConstructor and Description
public
X509v3CertificateBuilder(X500Name
the certificate issuer
issuer
,
BigInteger
the certificate serial number
serial
,
Date
the date before which the certificate is not valid
notBefore
,
Date
the date after which the certificate is not valid
notAfter
,
X500Name
the certificate subject
subject
,
SubjectPublicKeyInfo
the info structure for the public key to be associated with this certificate.
publicKeyInfo
)

Create a builder for a version 3 certificate.

public
X509v3CertificateBuilder(X500Name
the certificate issuer
issuer
,
BigInteger
the certificate serial number
serial
,
Date
the date before which the certificate is not valid
notBefore
,
Date
the date after which the certificate is not valid
notAfter
,
Locale
locale to be used for date interpretation.
dateLocale
,
X500Name
the certificate subject
subject
,
SubjectPublicKeyInfo
the info structure for the public key to be associated with this certificate.
publicKeyInfo
)

Create a builder for a version 3 certificate.

public
X509v3CertificateBuilder(X500Name
the certificate issuer
issuer
,
BigInteger
the certificate serial number
serial
,
Time
the Time before which the certificate is not valid
notBefore
,
Time
the Time after which the certificate is not valid
notAfter
,
X500Name
the certificate subject
subject
,
SubjectPublicKeyInfo
the info structure for the public key to be associated with this certificate.
publicKeyInfo
)

Create a builder for a version 3 certificate.

public
X509v3CertificateBuilder(X509CertificateHolder
template certificate to base the new one on.
template
)

Create a builder for a version 3 certificate, initialised with another certificate.

Method Summary

Modifier and TypeMethod and Description
public X509v3CertificateBuilder

Returns:

this builder object.
addExtension
(ASN1ObjectIdentifier
the OID defining the extension type.
oid
,
boolean
true if the extension is critical, false otherwise.
isCritical
,
ASN1Encodable
the ASN.1 structure that forms the extension's value.
value
)

Add a given extension field for the standard extensions tag (tag 3)

public X509v3CertificateBuilder

Returns:

this builder object.
addExtension
(Extension
the full extension value.
extension
)

Add a given extension field for the standard extensions tag (tag 3).

public X509v3CertificateBuilder

Returns:

this builder object.
addExtension
(ASN1ObjectIdentifier
the OID defining the extension type.
oid
,
boolean
true if the extension is critical, false otherwise.
isCritical
,
byte[]
a byte array representing the encoding of the extension value.
encodedValue
)

Add a given extension field for the standard extensions tag (tag 3) using a byte encoding of the extension value.

pack-priv static DERBitString
booleanToBitString(boolean[] id)

public X509CertificateHolder

Returns:

a holder containing the resulting signed certificate.
build
(ContentSigner
the content signer to be used to generate the signature validating the certificate.
signer
)

Generate an X.509 certificate, based on the current issuer and subject using the passed in signer.

public X509CertificateHolder

Returns:

a holder containing the resulting signed certificate.
build
(ContentSigner
the content signer to be used to generate the signature validating the certificate.
signer
,
boolean isCritical, ContentSigner
the content signer used to create the altSignatureAlgorithm and altSignatureValue extension.
altSigner
)

Generate an X.509 certificate, based on the current issuer and subject using the passed in signer and containing altSignatureAlgorithm and altSignatureValue extensions based on the passed altSigner.

public X509v3CertificateBuilder

Returns:

this builder object.
copyAndAddExtension
(ASN1ObjectIdentifier
the OID defining the extension type.
oid
,
boolean
true if the copied extension is to be marked as critical, false otherwise.
isCritical
,
X509CertificateHolder
the holder for the certificate that the extension is to be copied from.
certHolder
)

Add a given extension field for the standard extensions tag (tag 3) copying the extension value from another certificate.

private Extension
private static byte[]
private static Certificate
generateStructure(TBSCertificate tbsCert, AlgorithmIdentifier sigAlgId, byte[] signature)

public Extension

Returns:

true if a matching extension is present, false otherwise.
getExtension
(ASN1ObjectIdentifier
the OID for the extension we want to fetch.
oid
)

Return the current value of the extension for OID.

public boolean

Returns:

the Extension, or null if it is not present.
hasExtension
(ASN1ObjectIdentifier
the OID for the extension of interest.
oid
)

Return if the extension indicated by OID is present.

public X509v3CertificateBuilder

Returns:

this builder object.
removeExtension
(ASN1ObjectIdentifier
the OID of the extension to be removed.
oid
)

Remove the extension indicated by OID.

public X509v3CertificateBuilder

Returns:

this builder object.
replaceExtension
(ASN1ObjectIdentifier
the OID defining the extension type.
oid
,
boolean
true if the extension is critical, false otherwise.
isCritical
,
ASN1Encodable
the ASN.1 structure that forms the extension's value.
value
)

Replace the extension field for the passed in extension's extension ID with a new version.

public X509v3CertificateBuilder

Returns:

this builder object.
replaceExtension
(Extension
the full extension value.
extension
)

Replace the extension field for the passed in extension's extension ID with a new version.

public X509v3CertificateBuilder

Returns:

this builder object.
replaceExtension
(ASN1ObjectIdentifier
the OID defining the extension type.
oid
,
boolean
true if the extension is critical, false otherwise.
isCritical
,
byte[]
a byte array representing the encoding of the extension value.
encodedValue
)

Replace a given extension field for the standard extensions tag (tag 3) with the passed in byte encoded extension value.

public X509v3CertificateBuilder

Returns:

this builder object.
setIssuerUniqueID
(boolean[]
a boolean array representing the bits making up the issuerUniqueID.
uniqueID
)

Set the issuerUniqueID - note: it is very rare that it is correct to do this.

public X509v3CertificateBuilder

Returns:

this builder object.
setSubjectUniqueID
(boolean[]
a boolean array representing the bits making up the subjectUniqueID.
uniqueID
)

Set the subjectUniqueID - note: it is very rare that it is correct to do this.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

extGeneratorback to summary
private ExtensionsGenerator extGenerator
tbsGenback to summary
private V3TBSCertificateGenerator tbsGen

Constructor Detail

X509v3CertificateBuilderback to summary
public X509v3CertificateBuilder(X500Name issuer, BigInteger serial, Date notBefore, Date notAfter, X500Name subject, SubjectPublicKeyInfo publicKeyInfo)

Create a builder for a version 3 certificate.

Parameters
issuer:X500Name

the certificate issuer

serial:BigInteger

the certificate serial number

notBefore:Date

the date before which the certificate is not valid

notAfter:Date

the date after which the certificate is not valid

subject:X500Name

the certificate subject

publicKeyInfo:SubjectPublicKeyInfo

the info structure for the public key to be associated with this certificate.

X509v3CertificateBuilderback to summary
public X509v3CertificateBuilder(X500Name issuer, BigInteger serial, Date notBefore, Date notAfter, Locale dateLocale, X500Name subject, SubjectPublicKeyInfo publicKeyInfo)

Create a builder for a version 3 certificate. You may need to use this constructor if the default locale doesn't use a Gregorian calender so that the Time produced is compatible with other ASN.1 implementations.

Parameters
issuer:X500Name

the certificate issuer

serial:BigInteger

the certificate serial number

notBefore:Date

the date before which the certificate is not valid

notAfter:Date

the date after which the certificate is not valid

dateLocale:Locale

locale to be used for date interpretation.

subject:X500Name

the certificate subject

publicKeyInfo:SubjectPublicKeyInfo

the info structure for the public key to be associated with this certificate.

X509v3CertificateBuilderback to summary
public X509v3CertificateBuilder(X500Name issuer, BigInteger serial, Time notBefore, Time notAfter, X500Name subject, SubjectPublicKeyInfo publicKeyInfo)

Create a builder for a version 3 certificate.

Parameters
issuer:X500Name

the certificate issuer

serial:BigInteger

the certificate serial number

notBefore:Time

the Time before which the certificate is not valid

notAfter:Time

the Time after which the certificate is not valid

subject:X500Name

the certificate subject

publicKeyInfo:SubjectPublicKeyInfo

the info structure for the public key to be associated with this certificate.

X509v3CertificateBuilderback to summary
public X509v3CertificateBuilder(X509CertificateHolder template)

Create a builder for a version 3 certificate, initialised with another certificate.

Parameters
template:X509CertificateHolder

template certificate to base the new one on.

Method Detail

addExtensionback to summary
public X509v3CertificateBuilder addExtension(ASN1ObjectIdentifier oid, boolean isCritical, ASN1Encodable value) throws CertIOException

Add a given extension field for the standard extensions tag (tag 3)

Parameters
oid:ASN1ObjectIdentifier

the OID defining the extension type.

isCritical:boolean

true if the extension is critical, false otherwise.

value:ASN1Encodable

the ASN.1 structure that forms the extension's value.

Returns:X509v3CertificateBuilder

this builder object.

Exceptions
CertIOException:
if there is an issue with the new extension value.
IllegalArgumentException:
if the OID oid has already been used.
addExtensionback to summary
public X509v3CertificateBuilder addExtension(Extension extension) throws CertIOException

Add a given extension field for the standard extensions tag (tag 3).

Parameters
extension:Extension

the full extension value.

Returns:X509v3CertificateBuilder

this builder object.

Exceptions
CertIOException:
if there is an issue with the new extension value.
IllegalArgumentException:
if the OID oid has already been used.
addExtensionback to summary
public X509v3CertificateBuilder addExtension(ASN1ObjectIdentifier oid, boolean isCritical, byte[] encodedValue) throws CertIOException

Add a given extension field for the standard extensions tag (tag 3) using a byte encoding of the extension value.

Parameters
oid:ASN1ObjectIdentifier

the OID defining the extension type.

isCritical:boolean

true if the extension is critical, false otherwise.

encodedValue:byte[]

a byte array representing the encoding of the extension value.

Returns:X509v3CertificateBuilder

this builder object.

Exceptions
CertIOException:
if there is an issue with the new extension value.
IllegalArgumentException:
if the OID oid has already been allocated.
booleanToBitStringback to summary
pack-priv static DERBitString booleanToBitString(boolean[] id)
buildback to summary
public X509CertificateHolder build(ContentSigner signer)

Generate an X.509 certificate, based on the current issuer and subject using the passed in signer.

Parameters
signer:ContentSigner

the content signer to be used to generate the signature validating the certificate.

Returns:X509CertificateHolder

a holder containing the resulting signed certificate.

buildback to summary
public X509CertificateHolder build(ContentSigner signer, boolean isCritical, ContentSigner altSigner)

Generate an X.509 certificate, based on the current issuer and subject using the passed in signer and containing altSignatureAlgorithm and altSignatureValue extensions based on the passed altSigner.

Parameters
signer:ContentSigner

the content signer to be used to generate the signature validating the certificate.

altSigner:ContentSigner

the content signer used to create the altSignatureAlgorithm and altSignatureValue extension.

Returns:X509CertificateHolder

a holder containing the resulting signed certificate.

copyAndAddExtensionback to summary
public X509v3CertificateBuilder copyAndAddExtension(ASN1ObjectIdentifier oid, boolean isCritical, X509CertificateHolder certHolder)

Add a given extension field for the standard extensions tag (tag 3) copying the extension value from another certificate.

Parameters
oid:ASN1ObjectIdentifier

the OID defining the extension type.

isCritical:boolean

true if the copied extension is to be marked as critical, false otherwise.

certHolder:X509CertificateHolder

the holder for the certificate that the extension is to be copied from.

Returns:X509v3CertificateBuilder

this builder object.

doGetExtensionback to summary
private Extension doGetExtension(ASN1ObjectIdentifier oid)
generateSigback to summary
private static byte[] generateSig(ContentSigner signer, ASN1Object tbsObj) throws IOException
generateStructureback to summary
private static Certificate generateStructure(TBSCertificate tbsCert, AlgorithmIdentifier sigAlgId, byte[] signature)
getExtensionback to summary
public Extension getExtension(ASN1ObjectIdentifier oid)

Return the current value of the extension for OID.

Parameters
oid:ASN1ObjectIdentifier

the OID for the extension we want to fetch.

Returns:Extension

true if a matching extension is present, false otherwise.

hasExtensionback to summary
public boolean hasExtension(ASN1ObjectIdentifier oid)

Return if the extension indicated by OID is present.

Parameters
oid:ASN1ObjectIdentifier

the OID for the extension of interest.

Returns:boolean

the Extension, or null if it is not present.

removeExtensionback to summary
public X509v3CertificateBuilder removeExtension(ASN1ObjectIdentifier oid)

Remove the extension indicated by OID.

Parameters
oid:ASN1ObjectIdentifier

the OID of the extension to be removed.

Returns:X509v3CertificateBuilder

this builder object.

Exceptions
IllegalArgumentException:
if the extension to be removed is not present.
replaceExtensionback to summary
public X509v3CertificateBuilder replaceExtension(ASN1ObjectIdentifier oid, boolean isCritical, ASN1Encodable value) throws CertIOException

Replace the extension field for the passed in extension's extension ID with a new version.

Parameters
oid:ASN1ObjectIdentifier

the OID defining the extension type.

isCritical:boolean

true if the extension is critical, false otherwise.

value:ASN1Encodable

the ASN.1 structure that forms the extension's value.

Returns:X509v3CertificateBuilder

this builder object.

Exceptions
CertIOException:
if there is an issue with the new extension value.
IllegalArgumentException:
if the extension to be replaced is not present.
replaceExtensionback to summary
public X509v3CertificateBuilder replaceExtension(Extension extension) throws CertIOException

Replace the extension field for the passed in extension's extension ID with a new version.

Parameters
extension:Extension

the full extension value.

Returns:X509v3CertificateBuilder

this builder object.

Exceptions
CertIOException:
if there is an issue with the new extension value.
IllegalArgumentException:
if the extension to be replaced is not present.
replaceExtensionback to summary
public X509v3CertificateBuilder replaceExtension(ASN1ObjectIdentifier oid, boolean isCritical, byte[] encodedValue) throws CertIOException

Replace a given extension field for the standard extensions tag (tag 3) with the passed in byte encoded extension value.

Parameters
oid:ASN1ObjectIdentifier

the OID defining the extension type.

isCritical:boolean

true if the extension is critical, false otherwise.

encodedValue:byte[]

a byte array representing the encoding of the extension value.

Returns:X509v3CertificateBuilder

this builder object.

Exceptions
CertIOException:
if there is an issue with the new extension value.
IllegalArgumentException:
if the extension to be replaced is not present.
setIssuerUniqueIDback to summary
public X509v3CertificateBuilder setIssuerUniqueID(boolean[] uniqueID)

Set the issuerUniqueID - note: it is very rare that it is correct to do this.

Parameters
uniqueID:boolean[]

a boolean array representing the bits making up the issuerUniqueID.

Returns:X509v3CertificateBuilder

this builder object.

setSubjectUniqueIDback to summary
public X509v3CertificateBuilder setSubjectUniqueID(boolean[] uniqueID)

Set the subjectUniqueID - note: it is very rare that it is correct to do this.

Parameters
uniqueID:boolean[]

a boolean array representing the bits making up the subjectUniqueID.

Returns:X509v3CertificateBuilder

this builder object.