*/
public static void main(String[] args)
{
ASN1IA5String asn1Object;
ByteArrayOutputStream out;
DEREncoder encoder;
byte[] encodedAsn1Object;
StringBuffer buf;
String octet;
ASN1IA5String newAsn1Object;
ByteArrayInputStream in;
DERDecoder decoder;
ASN1Type asn1Type;
/* Create ASN.1 object.
*/
asn1Object = new ASN1IA5String("Hello World !");
/* Print the ASN.1 object to the standard output.
*/
System.out.println("ASN.1 object: ");
System.out.println(asn1Object.toString());
System.out.println();
/* Encoding process.
*/
/* Initialize an output stream to which the encoded data will be
* written.
*/
out = new ByteArrayOutputStream();
/* Initialize encoder instance with this output stream.
*/
encoder = new DEREncoder(out);
/* Byte array to store the encoded data.
*/
encodedAsn1Object = null;
try
{
/* Encoder reads the data stored in the variable asn1Object and
* encodes it writing the output to the output stream.
*/
asn1Object.encode(encoder);
/* Store the data in the output stream in a byte array. This array
* will be decoded later.
*/
encodedAsn1Object = out.toByteArray();
/* Close the stream.
*/
encoder.close();
}
catch (ASN1Exception e)
{
System.out.println("Error during encoding.");
e.printStackTrace();