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

org.bouncycastle.asn1

## Class DERSequenceGenerator

- java.lang.Object
- - org.bouncycastle.asn1.ASN1Generator
  - - org.bouncycastle.asn1.DERGenerator
    - - org.bouncycastle.asn1.DERSequenceGenerator

-     public class DERSequenceGenerator
      extends DERGenerator

  A stream generator for DER SEQUENCEs

- - ### Field Summary

    - ### Fields inherited from class org.bouncycastle.asn1.ASN1Generator

      `_out`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DERSequenceGenerator(java.io.OutputStream out)` Use the passed in stream as the target for the generator.
    `DERSequenceGenerator(java.io.OutputStream out, int tagNo, boolean isExplicit)` Use the passed in stream as the target for the generator, writing out the header tag for a tagged constructed SEQUENCE (possibly implicit).

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addObject(ASN1Encodable object)` Add an object to the SEQUENCE being generated.
    `void` | `addObject(ASN1Primitive primitive)` Add an ASN1.1 primitive to the SEQUENCE being generated.
    `void` | `close()` Close of the generator, writing out the SEQUENCE.
    `java.io.OutputStream` | `getRawOutputStream()` Return the target stream for the SEQUENCE.

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

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

- - ### Constructor Detail

    - #### DERSequenceGenerator

          public DERSequenceGenerator(java.io.OutputStream out)
                               throws java.io.IOException

      Use the passed in stream as the target for the generator.
      Parameters:
        `out` - target stream
      Throws:
        `java.io.IOException` - if the target stream cannot be written to.

    - #### DERSequenceGenerator

          public DERSequenceGenerator(java.io.OutputStream out,
                                      int tagNo,
                                      boolean isExplicit)
                               throws java.io.IOException

      Use the passed in stream as the target for the generator, writing out the header tag for a tagged constructed SEQUENCE (possibly implicit).
      Parameters:
        `out` - target stream
        `tagNo` - the tag number to introduce
        `isExplicit` - true if this is an explicitly tagged object, false otherwise.
      Throws:
        `java.io.IOException` - if the target stream cannot be written to.

  - ### Method Detail

    - #### addObject

          public void addObject(ASN1Encodable object)
                         throws java.io.IOException

      Add an object to the SEQUENCE being generated.
      Parameters:
        `object` - an ASN.1 encodable object to add.
      Throws:
        `java.io.IOException` - if the target stream cannot be written to or the object cannot be encoded.

    - #### addObject

          public void addObject(ASN1Primitive primitive)
                         throws java.io.IOException

      Add an ASN1.1 primitive to the SEQUENCE being generated.
      Parameters:
        `primitive` - an ASN.1 primitive to add.
      Throws:
        `java.io.IOException` - if the target stream cannot be written to or the primitive cannot be encoded.

    - #### getRawOutputStream

          public java.io.OutputStream getRawOutputStream()

      Return the target stream for the SEQUENCE.
      Specified by:
        `getRawOutputStream` in class `ASN1Generator`
      Returns:
        the OutputStream the SEQUENCE is being written to.

    - #### close

          public void close()
                     throws java.io.IOException

      Close of the generator, writing out the SEQUENCE.
      Throws:
        `java.io.IOException` - if the target stream cannot be written.