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

org.bouncycastle.asn1

## Class DEROctetString

- java.lang.Object
- - org.bouncycastle.asn1.ASN1Object
  - - org.bouncycastle.asn1.ASN1Primitive
    - - org.bouncycastle.asn1.ASN1OctetString
      - - org.bouncycastle.asn1.DEROctetString

- All Implemented Interfaces:
    ASN1Encodable, ASN1OctetStringParser, InMemoryRepresentable, Encodable

      public class DEROctetString
      extends ASN1OctetString

  Carrier class for a DER encoding OCTET STRING

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static DEROctetString` | `EMPTY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DEROctetString(ASN1Encodable obj)` Constructor from the encoding of an ASN.1 object.
    `DEROctetString(byte[] string)` Base constructor.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static DEROctetString` | `fromContents(byte[] contents)`
    `static DEROctetString` | `fromContentsOptional(byte[] contents)`
    `static DEROctetString` | `withContents(byte[] contents)`
    `static DEROctetString` | `withContentsOptional(byte[] contents)`

    - ### Methods inherited from class org.bouncycastle.asn1.ASN1OctetString

      `getInstance, getInstance, getLoadedObject, getOctets, getOctetsLength, getOctetStream, getTagged, hashCode, parser, toString`

    - ### Methods inherited from class org.bouncycastle.asn1.ASN1Primitive

      `encodeTo, encodeTo, equals, equals, equals, fromByteArray, fromStream, toASN1Primitive`

    - ### Methods inherited from class org.bouncycastle.asn1.ASN1Object

      `getEncoded, getEncoded, hasEncodedTagValue`

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.bouncycastle.asn1.ASN1Encodable

      `toASN1Primitive`

- - ### Field Detail

    - #### EMPTY

          public static final DEROctetString EMPTY

  - ### Constructor Detail

    - #### DEROctetString

          public DEROctetString(byte[] string)

      Base constructor.
      Parameters:
        `string` - the octets making up the octet string.

    - #### DEROctetString

          public DEROctetString(ASN1Encodable obj)
                         throws java.io.IOException

      Constructor from the encoding of an ASN.1 object.
      Parameters:
        `obj` - the object to be encoded.
      Throws:
        `java.io.IOException`

  - ### Method Detail

    - #### fromContents

          public static DEROctetString fromContents(byte[] contents)

    - #### fromContentsOptional

          public static DEROctetString fromContentsOptional(byte[] contents)

    - #### withContents

          public static DEROctetString withContents(byte[] contents)

    - #### withContentsOptional

          public static DEROctetString withContentsOptional(byte[] contents)