Package codec.asn1

Examples of codec.asn1.DEREncoder


     *                 defined by the installed providers.
     */
    public PublicKey getPublicKey() throws NoSuchAlgorithmException {
  ByteArrayOutputStream bos;
  X509EncodedKeySpec spec;
  DEREncoder enc;
  KeyFactory kf;
  String alg;

  try {
      bos = new ByteArrayOutputStream();
      enc = new DEREncoder(bos);
      encode(enc);
      spec = new X509EncodedKeySpec(bos.toByteArray());
      enc.close();

      alg = algorithm_.getAlgorithmOID().toString();
      kf = KeyFactory.getInstance(alg);

      return kf.generatePublic(spec);
View Full Code Here


     *                 if an internal error occurs while the key is encoded.
     *                 This should never happen.
     */
    protected void setRawKey(ASN1Type key) {
  ByteArrayOutputStream bos;
  DEREncoder enc;

  try {
      bos = new ByteArrayOutputStream();
      enc = new DEREncoder(bos);
      key.encode(enc);
      encodedKey_ = new ASN1BitString(bos.toByteArray(), 0);
      enc.close();
      set(1, encodedKey_);
  } catch (ASN1Exception e) {
      throw new InconsistentStateException("Internal, encoding error!");
  } catch (IOException e) {
      throw new InconsistentStateException(
View Full Code Here

     * @throws IOException DOCUMENT ME!
     */
    public byte[] getEncoded() throws ASN1Exception, IOException
    {
        ByteArrayOutputStream out;
        DEREncoder encoder;
        byte[] encodedAsn1Object;

        out         = new ByteArrayOutputStream();
        encoder     = new DEREncoder(out);

        this.encode(encoder);
        encodedAsn1Object = out.toByteArray();
        encoder.close();

        return encodedAsn1Object;
    }
View Full Code Here

     * @throws IOException DOCUMENT ME!
     */
    public byte[] getEncoded() throws ASN1Exception, IOException
    {
        ByteArrayOutputStream out;
        DEREncoder encoder;
        byte[] encodedAsn1Object;

        out         = new ByteArrayOutputStream();
        encoder     = new DEREncoder(out);

        this.encode(encoder);
        encodedAsn1Object = out.toByteArray();
        encoder.close();

        return encodedAsn1Object;
    }
View Full Code Here

     */
    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();
View Full Code Here

     * @throws IOException DOCUMENT ME!
     */
    public byte[] getEncoded() throws ASN1Exception, IOException
    {
        ByteArrayOutputStream out;
        DEREncoder encoder;
        byte[] encodedAsn1Object;

        out         = new ByteArrayOutputStream();
        encoder     = new DEREncoder(out);

        this.encode(encoder);
        encodedAsn1Object = out.toByteArray();
        encoder.close();

        return encodedAsn1Object;
    }
View Full Code Here

     * @throws IOException DOCUMENT ME!
     */
    public byte[] getEncoded() throws ASN1Exception, IOException
    {
        ByteArrayOutputStream out;
        DEREncoder encoder;
        byte[] encodedAsn1Object;

        out         = new ByteArrayOutputStream();
        encoder     = new DEREncoder(out);

        this.encode(encoder);
        encodedAsn1Object = out.toByteArray();
        encoder.close();

        return encodedAsn1Object;
    }
View Full Code Here

  if (registry == null) {
      registry = OIDRegistry.getGlobalOIDRegistry();
  }
  type_ = new ASN1ObjectIdentifier();
  values_ = new ASN1SetOf(new DefinedByResolver(registry, type_));

  add(type_);
  add(values_);
    }
View Full Code Here

    static public OIDRegistry getDefaultRegistry() {
  return default_;
    }

    public static void main(String[] argv) {
  OIDRegistry reg;
  int n;

  try {
      reg = PKCS12OIDRegistry.getDefaultRegistry();

      for (n = 0; n < argv.length; n++) {
    System.out.println(reg.getASN1Type(new ASN1ObjectIdentifier(
      argv[n])));
      }
  } catch (Exception e) {
      e.printStackTrace(System.err);
  }
View Full Code Here

    static public OIDRegistry getDefaultRegistry() {
  return default_;
    }

    public static void main(String[] argv) {
  OIDRegistry reg;
  int n;

  try {
      reg = PKCSRegistry.getDefaultRegistry();

      for (n = 0; n < argv.length; n++) {
    System.out.println(reg.getASN1Type(new ASN1ObjectIdentifier(
      argv[n])));
      }
  } catch (Exception e) {
      e.printStackTrace(System.err);
  }
View Full Code Here

TOP

Related Classes of codec.asn1.DEREncoder

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.