public class Asn1EncodingConverter
extends java.lang.Object
This class is a utility for converting indefinite length BER encoded ASN1 to definite length BER encoded ASN1.
The conversion is a multi-stage process. First, the BER encoded data is read to obtain the structure. Next, that structure is converted to the equivalent definite length encoding. Finally, the BER encoded data is read again, and written to another stream using the calculated definite length encoding.
To perform the conversion, the entire ASN1 structure must be read in to memory.
Memory requirements will vary depending on the complexity of the structure.
This class operates well when constructed string types are constructed using
runs of the same length, such as those
produced by PKCS7EncodeStream when the block size is set. If
the ASN1 uses many different tags and length encodings, OutOfMemoryErrors
may occur.
There are some important limitations to this class:
| Modifier and Type | Method and Description |
|---|---|
static void |
convertEncoding(java.io.InputStream is1,
java.io.InputStream is2,
java.io.OutputStream os)
Converts the ASN1 data in a stream to definite length encoding and writes
it to another stream.
|
static void |
convertEncoding(java.lang.String inFileName,
java.lang.String outFileName)
Converts the ASN1 data in a file to definite length encoding and writes
it to another file.
|
public static void convertEncoding(java.lang.String inFileName,
java.lang.String outFileName)
throws CodingException,
java.io.IOException
inFileName - the name of the file that contains the indefinite length encoded data.outFileName - the name of the file to which the definite length encoded
data will be written. This must be refer to a different file
from inFileNameCodingException - if the data in inFileName cannot be parsed as ASN1.java.io.IOException - if there is any IO problem reading or writing the files.public static void convertEncoding(java.io.InputStream is1,
java.io.InputStream is2,
java.io.OutputStream os)
throws CodingException,
java.io.IOException
is1 - the stream from which the structure of the ASN1 encoded data will be
parsed.is2 - the stream from which the ASN1 encoded data will be read. This stream must
contain identical data to is1, but not be the same stream. If
the data is not identical, the data written to os will be
meaningless.os - the output stream to write the definite length encoded data to.CodingException - if the data in is1 cannot be parsed as ASN1.java.io.IOException - if there is any IO problem reading or writing the streams.