public class DerOutputStream extends java.io.ByteArrayOutputStream implements DerEncoder
At this time, this class supports only a subset of the types of DER data encodings which are defined. That subset is sufficient for generating most X.509 certificates.
| Constructor and Description |
|---|
DerOutputStream()
Construct an DER output stream.
|
DerOutputStream(int size)
Construct an DER output stream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
derEncode(java.io.OutputStream out)
Write the current contents of this
DerOutputStream
to an OutputStream. |
void |
putBitString(byte[] bits)
Marshals a DER bit string on the output stream.
|
void |
putBMPString(java.lang.String s)
Marshals a string as a DER encoded BMPString.
|
void |
putBoolean(boolean val)
Marshals a DER boolean on the output stream.
|
void |
putDerValue(DerValue val)
Marshals pre-encoded DER value onto the output stream.
|
void |
putEnumerated(int i)
Marshals a DER enumerated on the output stream.
|
void |
putGeneralizedTime(java.util.Date d)
Marshals a DER Generalized Time/date value.
|
void |
putGeneralString(java.lang.String s)
Marshals a string as a DER encoded GeneralString.
|
void |
putIA5String(java.lang.String s)
Marshals a string as a DER encoded IA5String.
|
void |
putInteger(java.math.BigInteger i)
Marshals a DER integer on the output stream.
|
void |
putInteger(int i)
Marshals a DER integer on the output stream.
|
void |
putInteger(java.lang.Integer i)
Marshals a DER integer on the output stream.
|
void |
putLength(int len)
Put the encoding of the length in the stream.
|
void |
putNull()
Marshals a DER "null" value on the output stream.
|
void |
putOctetString(byte[] octets)
DER-encodes an ASN.1 OCTET STRING value on the output stream.
|
void |
putOID(ObjectIdentifier oid)
Marshals an object identifier (OID) on the output stream.
|
void |
putOrderedSet(byte tag,
DerEncoder[] set)
Marshals the contents of a set on the output stream.
|
void |
putOrderedSetOf(byte tag,
DerEncoder[] set)
Marshals the contents of a set on the output stream.
|
void |
putPrintableString(java.lang.String s)
Marshals a string as a DER encoded PrintableString.
|
void |
putSequence(DerValue[] seq)
Marshals a sequence on the output stream.
|
void |
putSet(DerValue[] set)
Marshals the contents of a set on the output stream without
ordering the elements.
|
void |
putT61String(java.lang.String s)
Marshals a string as a DER encoded T61String.
|
void |
putTag(byte tagClass,
boolean form,
byte val)
Put the tag of the attribute in the stream.
|
void |
putTruncatedUnalignedBitString(BitArray ba)
Marshals a truncated DER bit string on the output stream.
|
void |
putUnalignedBitString(BitArray ba)
Marshals a DER bit string on the output stream.
|
void |
putUTCTime(java.util.Date d)
Marshals a DER UTC time/date value.
|
void |
putUTF8String(java.lang.String s)
Marshals a string as a DER encoded UTF8String.
|
void |
write(byte tag,
byte[] buf)
Writes tagged, pre-marshaled data.
|
void |
write(byte tag,
DerOutputStream out)
Writes tagged data using buffer-to-buffer copy.
|
void |
writeImplicit(byte tag,
DerOutputStream value)
Writes implicitly tagged data using buffer-to-buffer copy.
|
public DerOutputStream(int size)
size - how large a buffer to preallocate.public DerOutputStream()
public void write(byte tag,
byte[] buf)
throws java.io.IOException
tag - the DER value tag for the data, such as
DerValue.tag_Sequencebuf - buffered data, which must be DER-encodedjava.io.IOExceptionpublic void write(byte tag,
DerOutputStream out)
throws java.io.IOException
tag - the DER value tag for the data, such as
DerValue.tag_Sequenceout - buffered datajava.io.IOExceptionpublic void writeImplicit(byte tag,
DerOutputStream value)
throws java.io.IOException
tag - the DER value of the context-specific tag that replaces
original tag of the value in the output, such as in
<field> [N] IMPLICIT <type>
For example, FooLength [1] IMPLICIT INTEGER, with value=4;
would be encoded as "81 01 04" whereas in explicit
tagging it would be encoded as "A1 03 02 01 04".
Notice that the tag is A1 and not 81, this is because with
explicit tagging the form is always constructed.value - original value being implicitly taggedjava.io.IOExceptionpublic void putDerValue(DerValue val) throws java.io.IOException
java.io.IOExceptionpublic void putBoolean(boolean val)
throws java.io.IOException
java.io.IOExceptionpublic void putEnumerated(int i)
throws java.io.IOException
i - the enumerated value.java.io.IOExceptionpublic void putInteger(java.math.BigInteger i)
throws java.io.IOException
i - the integer in the form of a BigInteger.java.io.IOExceptionpublic void putInteger(java.lang.Integer i)
throws java.io.IOException
i - the integer in the form of an Integer.java.io.IOExceptionpublic void putInteger(int i)
throws java.io.IOException
i - the integer.java.io.IOExceptionpublic void putBitString(byte[] bits)
throws java.io.IOException
bits - the bit string, MSB firstjava.io.IOExceptionpublic void putUnalignedBitString(BitArray ba) throws java.io.IOException
ba - the bit string, MSB firstjava.io.IOExceptionpublic void putTruncatedUnalignedBitString(BitArray ba) throws java.io.IOException
ba - the bit string, MSB firstjava.io.IOExceptionpublic void putOctetString(byte[] octets)
throws java.io.IOException
octets - the octet stringjava.io.IOExceptionpublic void putNull()
throws java.io.IOException
java.io.IOExceptionpublic void putOID(ObjectIdentifier oid) throws java.io.IOException
java.io.IOExceptionpublic void putSequence(DerValue[] seq) throws java.io.IOException
java.io.IOExceptionpublic void putSet(DerValue[] set) throws java.io.IOException
java.io.IOExceptionpublic void putOrderedSetOf(byte tag,
DerEncoder[] set)
throws java.io.IOException
java.io.IOExceptionpublic void putOrderedSet(byte tag,
DerEncoder[] set)
throws java.io.IOException
java.io.IOExceptionpublic void putUTF8String(java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic void putPrintableString(java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic void putT61String(java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic void putIA5String(java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic void putBMPString(java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic void putGeneralString(java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic void putUTCTime(java.util.Date d)
throws java.io.IOException
YYMMDDhhmmss{Z|+hhmm|-hhmm} ... emits only using Zulu time and with seconds (even if seconds=0) as per RFC 3280.
java.io.IOExceptionpublic void putGeneralizedTime(java.util.Date d)
throws java.io.IOException
YYYYMMDDhhmmss{Z|+hhmm|-hhmm} ... emits only using Zulu time and with seconds (even if seconds=0) as per RFC 3280.
java.io.IOExceptionpublic void putLength(int len)
throws java.io.IOException
len - the length of the attribute.java.io.IOException - on writing errors.public void putTag(byte tagClass,
boolean form,
byte val)
tagClass - the tag class type, one of UNIVERSAL, CONTEXT,
APPLICATION or PRIVATEform - if true, the value is constructed, otherwise it is
primitive.val - the tag valuepublic void derEncode(java.io.OutputStream out)
throws java.io.IOException
DerOutputStream
to an OutputStream.derEncode in interface DerEncoderout - the stream on which the DER encoding is written.java.io.IOException - on output error.Copyright © 2025. All rights reserved.