Package codec.asn1

Examples of codec.asn1.DERDecoder


     *          null.
     */
    public boolean[] getKeyUsage() {
  boolean[] res = null;
  byte[] ext_value;
  DERDecoder dec;
  ByteArrayInputStream bais;
  ASN1BitString bits;

  String ku_oid = "2.5.29.15";

  // get the extension "key usage"
  ext_value = getExtensionValue(ku_oid);

  // is it present?
  if (ext_value != null) {

      // read the extension value through a byte array input stream
      bais = new ByteArrayInputStream(ext_value);

      try {

    // build outer sequence
    bits = new ASN1BitString();

    dec = new DERDecoder(bais);

    /*
     * Replaced the construct dec.readX(X) by the correct use of
     * X.decode(dec). The latter takes into consideration any
     * special decoding steps (such as optimizations) done by the
View Full Code Here


     * @throws IOException DOCUMENT ME!
     */
    public void decode(byte[] encodedData) throws ASN1Exception, IOException
    {
        ByteArrayInputStream in;
        DERDecoder decoder;

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

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

        /* Decode the data in the input stream and stored it in the member
         * variables of this class that represent the components of the
         * corresponding ASN.1 type.
         */
        this.decode(decoder);

        /* Close the stream.
         */
        decoder.close();
    }
View Full Code Here

     * @throws IOException DOCUMENT ME!
     */
    public void decode(byte[] encodedData) throws ASN1Exception, IOException
    {
        ByteArrayInputStream in;
        DERDecoder decoder;

        in          = new ByteArrayInputStream(encodedData);
        decoder     = new DERDecoder(in);

        this.decode(decoder);
        decoder.close();
    }
View Full Code Here

     * Constructor on an input stream that delivers the DER-encoded certificate
     * revocation list.
     */
    public X509Crl(InputStream is) throws ASN1Exception, IOException {
  this();
  this.decode(new DERDecoder(is));
    }
View Full Code Here

     */
    public void setPublicKey(PublicKey key) throws InvalidKeyException {
  if (key == null)
      throw new NullPointerException("Key is null!");

  DERDecoder dec;

  clear();

  algorithm_ = new AlgorithmIdentifier();
  add(algorithm_);
  encodedKey_ = new ASN1BitString();
  add(encodedKey_);

  try {
      dec = new DERDecoder(new ByteArrayInputStream(key.getEncoded()));

      decode(dec);
      dec.close();
  } catch (IOException e) {
      throw new InvalidKeyException("Caught IOException!");
  } catch (ASN1Exception e) {
      throw new InvalidKeyException("Bad encoding!");
  }
View Full Code Here

     * encodings.
     *
     * @return The raw key decoded according to DER.
     */
    public ASN1Type getDecodedRawKey() throws CorruptedCodeException {
  DERDecoder dec;
  ASN1Type raw;

  try {
      dec = new DERDecoder(new ByteArrayInputStream(encodedKey_
        .getBytes()));

      raw = dec.readType();
      dec.close();

      return raw;
  } catch (ASN1Exception e) {
      throw new CorruptedCodeException("Cannot decode raw key!");
  } catch (IOException e) {
View Full Code Here

     * @throws IOException DOCUMENT ME!
     */
    public void decode(byte[] encodedData) throws ASN1Exception, IOException
    {
        ByteArrayInputStream in;
        DERDecoder decoder;

        in          = new ByteArrayInputStream(encodedData);
        decoder     = new DERDecoder(in);

        this.decode(decoder);
        decoder.close();
    }
View Full Code Here

        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.
         */
        System.out.println("Alternative decoding procedure:");

        /* Variable to store the data that will be decoded. Its type is not
         * determined.
         */
        asn1Type     = null;

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

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

        try
        {
            /* Decoder returns a Java object of the corresponding CODEC class
             * and already containing the decoded data.
             */
            asn1Type = decoder.readType();
            decoder.close();
        }
        catch (ASN1Exception e)
        {
            System.out.println("Error during decoding.");
            e.printStackTrace();
View Full Code Here

     * @throws IOException DOCUMENT ME!
     */
    public void decode(byte[] encodedData) throws ASN1Exception, IOException
    {
        ByteArrayInputStream in;
        DERDecoder decoder;

        in          = new ByteArrayInputStream(encodedData);
        decoder     = new DERDecoder(in);

        this.decode(decoder);
        decoder.close();
    }
View Full Code Here

     * @throws IOException DOCUMENT ME!
     */
    public void decode(byte[] encodedData) throws ASN1Exception, IOException
    {
        ByteArrayInputStream in;
        DERDecoder decoder;

        in          = new ByteArrayInputStream(encodedData);
        decoder     = new DERDecoder(in);

        this.decode(decoder);
        decoder.close();
    }
View Full Code Here

TOP

Related Classes of codec.asn1.DERDecoder

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.