ExtensionsGenerator (Bouncy Castle Library 1.85 API Specification)
Date: 2026-07-12

org.bouncycastle.asn1.x509

## Class ExtensionsGenerator

- java.lang.Object
- - org.bouncycastle.asn1.x509.ExtensionsGenerator

-     public class ExtensionsGenerator
      extends java.lang.Object

  Generator for X.509 extensions

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExtensionsGenerator()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addExtension(ASN1ObjectIdentifier oid, boolean critical, ASN1Encodable value)` Add an extension with the given oid and the passed in value to be included in the OCTET STRING associated with the extension.
    `void` | `addExtension(ASN1ObjectIdentifier oid, boolean critical, byte[] value)` Add an extension with the given oid and the passed in byte array to be wrapped in the OCTET STRING associated with the extension.
    `void` | `addExtension(Extension extension)` Add a given extension.
    `void` | `addExtension(Extensions extensions)` Deprecated. Use addExtensions instead.
    `void` | `addExtensions(Extensions extensions)`
    `Extensions` | `generate()` Generate an Extensions object based on the current state of the generator.
    `Extension` | `getExtension(ASN1ObjectIdentifier oid)` Return the current value of the extension for OID.
    `boolean` | `hasExtension(ASN1ObjectIdentifier oid)` Return if the extension indicated by OID is present.
    `boolean` | `isEmpty()` Return true if there are no extension present in this generator.
    `void` | `removeExtension(ASN1ObjectIdentifier oid)` Remove a given extension.
    `void` | `replaceExtension(ASN1ObjectIdentifier oid, boolean critical, ASN1Encodable value)` Replace an extension with the given oid and the passed in value to be included in the OCTET STRING associated with the extension.
    `void` | `replaceExtension(ASN1ObjectIdentifier oid, boolean critical, byte[] value)` Replace an extension with the given oid and the passed in byte array to be wrapped in the OCTET STRING associated with the extension.
    `void` | `replaceExtension(Extension extension)` Replace a given extension.
    `void` | `reset()` Reset the generator

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ExtensionsGenerator

          public ExtensionsGenerator()

  - ### Method Detail

    - #### reset

          public void reset()

      Reset the generator

    - #### addExtension

          public void addExtension(ASN1ObjectIdentifier oid,
                                   boolean critical,
                                   ASN1Encodable value)
                            throws java.io.IOException

      Add an extension with the given oid and the passed in value to be included in the OCTET STRING associated with the extension.
      Parameters:
        `oid` - OID for the extension.
        `critical` - true if critical, false otherwise.
        `value` - the ASN.1 object to be included in the extension.
      Throws:
        `java.io.IOException`

    - #### addExtension

          public void addExtension(ASN1ObjectIdentifier oid,
                                   boolean critical,
                                   byte[] value)

      Add an extension with the given oid and the passed in byte array to be wrapped in the OCTET STRING associated with the extension.
      Parameters:
        `oid` - OID for the extension.
        `critical` - true if critical, false otherwise.
        `value` - the byte array to be wrapped.

    - #### addExtension

          public void addExtension(Extension extension)

      Add a given extension.
      Parameters:
        `extension` - the full extension value.

    - #### addExtension

          public void addExtension(Extensions extensions)

      Deprecated. Use addExtensions instead.

    - #### addExtensions

          public void addExtensions(Extensions extensions)

    - #### replaceExtension

          public void replaceExtension(ASN1ObjectIdentifier oid,
                                       boolean critical,
                                       ASN1Encodable value)
                                throws java.io.IOException

      Replace an extension with the given oid and the passed in value to be included in the OCTET STRING associated with the extension.
      Parameters:
        `oid` - OID for the extension.
        `critical` - true if critical, false otherwise.
        `value` - the ASN.1 object to be included in the extension.
      Throws:
        `java.io.IOException`

    - #### replaceExtension

          public void replaceExtension(ASN1ObjectIdentifier oid,
                                       boolean critical,
                                       byte[] value)

      Replace an extension with the given oid and the passed in byte array to be wrapped in the OCTET STRING associated with the extension.
      Parameters:
        `oid` - OID for the extension.
        `critical` - true if critical, false otherwise.
        `value` - the byte array to be wrapped.

    - #### replaceExtension

          public void replaceExtension(Extension extension)

      Replace a given extension.
      Parameters:
        `extension` - the full extension value.

    - #### removeExtension

          public void removeExtension(ASN1ObjectIdentifier oid)

      Remove a given extension.
      Parameters:
        `oid` - OID for the extension to remove.

    - #### hasExtension

          public boolean hasExtension(ASN1ObjectIdentifier oid)

      Return if the extension indicated by OID is present.
      Parameters:
        `oid` - the OID for the extension of interest.
      Returns:
        true if a matching extension is present, false otherwise.

    - #### getExtension

          public Extension getExtension(ASN1ObjectIdentifier oid)

      Return the current value of the extension for OID.
      Parameters:
        `oid` - the OID for the extension we want to fetch.
      Returns:
        the Extension, or null if it is not present.

    - #### isEmpty

          public boolean isEmpty()

      Return true if there are no extension present in this generator.
      Returns:
        true if empty, false otherwise

    - #### generate

          public Extensions generate()

      Generate an Extensions object based on the current state of the generator.
      Returns:
        an X09Extensions object.