Package codec.asn1

Examples of codec.asn1.ASN1IA5String


     *
     * @param args DOCUMENT ME!
     */
    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();
        }
        catch (IOException e)
        {
            System.out.println("Error during encoding.");
            e.printStackTrace();
        }


        /* Print the encoded data to the standard output in hexadecimal
         * representation.
         */
        buf = new StringBuffer();

        for (int i = 0; i < encodedAsn1Object.length; i++)
        {
            octet = Integer.toHexString(encodedAsn1Object[i] & 0xff);
            buf.append(" 0x");
            if (octet.length() == 1)
            {
                buf.append('0');
            }
            buf.append(octet);
        }

        System.out.println("Encoded ASN.1 object:");
        System.out.println(buf.toString());
        System.out.println();


        /* Decoding process.
         */
        /* Create new empty object of the expected class. This object will
         * store the decoded values.
         */
        newAsn1Object     = new ASN1IA5String();

        /* Initialize input stream containing the encoded data.
         */
        in     = new ByteArrayInputStream(encodedAsn1Object);

        /* Initialize decoder instance with this input stream.
         */
        decoder = new DERDecoder(in);

        try
        {
            /* Decode the data in the input stream and stored it in
             * newAsn1Object.
             */
            newAsn1Object.decode(decoder);

            /* Close the stream.
             */
            decoder.close();
        }
        catch (ASN1Exception e)
        {
            System.out.println("Error during decoding.");
            e.printStackTrace();
        }
        catch (IOException e)
        {
            System.out.println("Error during decoding.");
            e.printStackTrace();
        }

        /* Print the new ASN.1 object to the standard output.
         */
        System.out.println(
            "New ASN.1 object got by decoding the previous bytes:");
        System.out.println(newAsn1Object.toString());
        System.out.println();


        /* Alternative decoding procedure without assuming to know the ASN.1
         * type to be decoded.
View Full Code Here


     */
    public Person(String title, String name)
    {
        super(2);

        title_     = new ASN1IA5String(title);
        name_      = new ASN1IA5String(name);
    }
View Full Code Here

     */
    public Person(String name)
    {
        super(1);

        name_ = new ASN1IA5String(name);
    }
View Full Code Here

     */
    public Person()
    {
        super(2);

        title_     = new ASN1IA5String();
        name_      = new ASN1IA5String();

        add(new ASN1TaggedType(TITLE_TAG, title_, true, true));
        add(name_);
    }
View Full Code Here

     *
     * @param title DOCUMENT ME!
     */
    public void setTitle(String title)
    {
        title_ = new ASN1IA5String(title);
    }
View Full Code Here

     *
     * @param name DOCUMENT ME!
     */
    public void setName(String name)
    {
        name_ = new ASN1IA5String(name);
    }
View Full Code Here

        super(2);

        quantity_ = new ASN1Integer(quantity);
        if (!currency.equals(DEFAULT_CURRENCY))
        {
            currency_ = new ASN1IA5String(currency);
        }
    }
View Full Code Here

    public Payment()
    {
        super(3);

        quantity_     = new ASN1Integer();
        currency_     = new ASN1IA5String();

        add(quantity_);
        add(new ASN1TaggedType(CURRENCY_TAG, currency_, true, true));
    }
View Full Code Here

     */
    public void setCurrency(String currency)
    {
        if (!currency.equals(DEFAULT_CURRENCY))
        {
            currency_ = new ASN1IA5String(currency);
        }
    }
View Full Code Here

     */
    public String toString()
    {
        if (currency_ == null)
        {
            currency_ = new ASN1IA5String(DEFAULT_CURRENCY);
            map();
            currency_ = null;
            return super.toString();
        }
        else
        {
            if (currency_.getString() == "")
            {
                currency_ = new ASN1IA5String(DEFAULT_CURRENCY);
                map();
                currency_ = new ASN1IA5String();
                return super.toString();
            }
            else
            {
                map();
View Full Code Here

TOP

Related Classes of codec.asn1.ASN1IA5String

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.