示例#1
0
  /**
   * Encode the CertPath using PKIPATH format.
   *
   * @return a byte array containing the binary encoding of the PkiPath object
   * @exception CertificateEncodingException if an exception occurs
   */
  private byte[] encodePKIPATH() throws CertificateEncodingException {

    ListIterator<X509Certificate> li = certs.listIterator(certs.size());
    try {
      DerOutputStream bytes = new DerOutputStream();
      // encode certs in reverse order (trust anchor to target)
      // according to PkiPath format
      while (li.hasPrevious()) {
        X509Certificate cert = li.previous();
        // check for duplicate cert
        if (certs.lastIndexOf(cert) != certs.indexOf(cert)) {
          throw new CertificateEncodingException("Duplicate Certificate");
        }
        // get encoded certificates
        byte[] encoded = cert.getEncoded();
        bytes.write(encoded);
      }

      // Wrap the data in a SEQUENCE
      DerOutputStream derout = new DerOutputStream();
      derout.write(DerValue.tag_SequenceOf, bytes);
      return derout.toByteArray();

    } catch (IOException ioe) {
      throw new CertificateEncodingException("IOException encoding " + "PkiPath data: " + ioe, ioe);
    }
  }
 // Encode this extension value
 private void encodeThis() throws IOException {
   if (crlNumber == null) {
     this.extensionValue = null;
     return;
   }
   DerOutputStream os = new DerOutputStream();
   os.putInteger(this.crlNumber);
   this.extensionValue = os.toByteArray();
 }
 /**
  * Write the extension to the DerOutputStream.
  *
  * @param out the DerOutputStream to write the extension to.
  * @exception IOException on encoding errors.
  */
 public void encode(OutputStream out) throws IOException {
   DerOutputStream tmp = new DerOutputStream();
   if (extensionValue == null) {
     extensionId = PKIXExtensions.CertificatePolicies_Id;
     critical = false;
     encodeThis();
   }
   super.encode(tmp);
   out.write(tmp.toByteArray());
 }
 /**
  * Write the extension to the DerOutputStream.
  *
  * @param out the DerOutputStream to write the extension to.
  * @exception IOException on encoding errors.
  */
 public void encode(OutputStream out) throws IOException {
   DerOutputStream tmp = new DerOutputStream();
   if (this.extensionValue == null) {
     this.extensionId = PKIXExtensions.SubjectInfoAccess_Id;
     this.critical = false;
     encodeThis();
   }
   super.encode(tmp);
   out.write(tmp.toByteArray());
 }
示例#5
0
  /**
   * Returns the ASN.1 encoding of this object.
   *
   * @return the ASN.1 encoding.
   * @exception IOException if error occurs when constructing its ASN.1 encoding.
   */
  public byte[] getEncoded() throws NoSuchAlgorithmException, IOException {
    if (this.encoded != null) return this.encoded.clone();

    DerOutputStream out = new DerOutputStream();
    DerOutputStream tmp = new DerOutputStream();

    DerOutputStream tmp2 = new DerOutputStream();
    // encode encryption algorithm
    AlgorithmId algid = AlgorithmId.get(digestAlgorithmName);
    algid.encode(tmp2);

    // encode digest data
    tmp2.putOctetString(digest);

    tmp.write(DerValue.tag_Sequence, tmp2);

    // encode salt
    tmp.putOctetString(macSalt);

    // encode iterations
    tmp.putInteger(iterations);

    // wrap everything into a SEQUENCE
    out.write(DerValue.tag_Sequence, tmp);
    this.encoded = out.toByteArray();

    return this.encoded.clone();
  }
示例#6
0
  /**
   * Returns the encoded SPNEGO token Note: inserts the required CHOICE tags
   *
   * @return the encoded token
   * @exception GSSException
   */
  byte[] getEncoded() throws IOException, GSSException {

    // get the token encoded value
    DerOutputStream token = new DerOutputStream();
    token.write(encode());

    // now insert the CHOICE
    switch (tokenType) {
      case NEG_TOKEN_INIT_ID:
        // Insert CHOICE of Negotiation Token
        DerOutputStream initToken = new DerOutputStream();
        initToken.write(
            DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) NEG_TOKEN_INIT_ID), token);
        return initToken.toByteArray();

      case NEG_TOKEN_TARG_ID:
        // Insert CHOICE of Negotiation Token
        DerOutputStream targToken = new DerOutputStream();
        targToken.write(
            DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) NEG_TOKEN_TARG_ID), token);
        return targToken.toByteArray();
      default:
        return token.toByteArray();
    }
  }
 /**
  * Return the DER encoded form of the certificate pair.
  *
  * @return The encoded form of the certificate pair.
  * @throws CerticateEncodingException If an encoding exception occurs.
  */
 public byte[] getEncoded() throws CertificateEncodingException {
   try {
     if (encoded == null) {
       DerOutputStream tmp = new DerOutputStream();
       emit(tmp);
       encoded = tmp.toByteArray();
     }
   } catch (IOException ex) {
     throw new CertificateEncodingException(ex.toString());
   }
   return encoded;
 }
 /**
  * Write the PolicyInformation to the DerOutputStream.
  *
  * @param out the DerOutputStream to write the extension to.
  * @exception IOException on encoding errors.
  */
 public void encode(DerOutputStream out) throws IOException {
   DerOutputStream tmp = new DerOutputStream();
   policyIdentifier.encode(tmp);
   if (!policyQualifiers.isEmpty()) {
     DerOutputStream tmp2 = new DerOutputStream();
     for (PolicyQualifierInfo pq : policyQualifiers) {
       tmp2.write(pq.getEncoded());
     }
     tmp.write(DerValue.tag_Sequence, tmp2);
   }
   out.write(DerValue.tag_Sequence, tmp);
 }
 // Encode this extension value
 private void encodeThis() throws IOException {
   if (accessDescriptions.isEmpty()) {
     this.extensionValue = null;
   } else {
     DerOutputStream ads = new DerOutputStream();
     for (AccessDescription accessDescription : accessDescriptions) {
       accessDescription.encode(ads);
     }
     DerOutputStream seq = new DerOutputStream();
     seq.write(DerValue.tag_Sequence, ads);
     this.extensionValue = seq.toByteArray();
   }
 }
  /** Write the extension to the DerOutputStream. (Also called by the subclass) */
  protected void encode(OutputStream out, ObjectIdentifier extensionId, boolean isCritical)
      throws IOException {

    DerOutputStream tmp = new DerOutputStream();

    if (this.extensionValue == null) {
      this.extensionId = extensionId;
      this.critical = isCritical;
      encodeThis();
    }
    super.encode(tmp);
    out.write(tmp.toByteArray());
  }
示例#11
0
 /**
  * Encode the CertPath using PKCS#7 format.
  *
  * @return a byte array containing the binary encoding of the PKCS#7 object
  * @exception CertificateEncodingException if an exception occurs
  */
 private byte[] encodePKCS7() throws CertificateEncodingException {
   PKCS7 p7 =
       new PKCS7(
           new AlgorithmId[0],
           new ContentInfo(ContentInfo.DATA_OID, null),
           certs.toArray(new X509Certificate[certs.size()]),
           new SignerInfo[0]);
   DerOutputStream derout = new DerOutputStream();
   try {
     p7.encodeSignedData(derout);
   } catch (IOException ioe) {
     throw new CertificateEncodingException(ioe.getMessage());
   }
   return derout.toByteArray();
 }
  // Encode this extension value.
  private void encodeThis() throws IOException {
    if (certPolicies == null || certPolicies.isEmpty()) {
      this.extensionValue = null;
    } else {
      DerOutputStream os = new DerOutputStream();
      DerOutputStream tmp = new DerOutputStream();

      for (PolicyInformation info : certPolicies) {
        info.encode(tmp);
      }

      os.write(DerValue.tag_Sequence, tmp);
      this.extensionValue = os.toByteArray();
    }
  }
示例#13
0
 /*     */ private NamedCurve(
     String paramString,
     ObjectIdentifier paramObjectIdentifier,
     EllipticCurve paramEllipticCurve,
     ECPoint paramECPoint,
     BigInteger paramBigInteger,
     int paramInt)
     /*     */ throws IOException
       /*     */ {
   /*  58 */ super(paramEllipticCurve, paramECPoint, paramBigInteger, paramInt);
   /*  59 */ this.name = paramString;
   /*  60 */ this.oid = paramObjectIdentifier;
   /*     */
   /*  62 */ DerOutputStream localDerOutputStream = new DerOutputStream();
   /*  63 */ localDerOutputStream.putOID(paramObjectIdentifier);
   /*  64 */ this.encoded = localDerOutputStream.toByteArray();
   /*     */ }
示例#14
0
  /**
   * Encode the policy set to the output stream.
   *
   * @param out the DerOutputStream to encode the data to.
   */
  public void encode(DerOutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();

    for (int i = 0; i < ids.size(); i++) {
      ids.elementAt(i).encode(tmp);
    }
    out.write(DerValue.tag_Sequence, tmp);
  }
示例#15
0
  /**
   * Encodes an MethodData object.
   *
   * @return the byte array of encoded MethodData object.
   * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
   * @exception IOException if an I/O error occurs while reading encoded data.
   */
  public byte[] asn1Encode() throws Asn1Exception, IOException {
    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();
    temp.putInteger(BigInteger.valueOf(methodType));
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
    if (methodData != null) {
      temp = new DerOutputStream();
      temp.putOctetString(methodData);
      bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
  }
  /* Translate to encoded bytes */
  private void emit(DerOutputStream out) throws IOException, CertificateEncodingException {
    DerOutputStream tagged = new DerOutputStream();

    if (forward != null) {
      DerOutputStream tmp = new DerOutputStream();
      tmp.putDerValue(new DerValue(forward.getEncoded()));
      tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_FORWARD), tmp);
    }

    if (reverse != null) {
      DerOutputStream tmp = new DerOutputStream();
      tmp.putDerValue(new DerValue(reverse.getEncoded()));
      tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_REVERSE), tmp);
    }

    out.write(DerValue.tag_Sequence, tagged);
  }
 /*     */ private void putOrderedSet(
     byte paramByte, DerEncoder[] paramArrayOfDerEncoder, Comparator<byte[]> paramComparator)
     /*     */ throws IOException
       /*     */ {
   /* 375 */ DerOutputStream[] arrayOfDerOutputStream =
       new DerOutputStream[paramArrayOfDerEncoder.length];
   /*     */
   /* 377 */ for (int i = 0; i < paramArrayOfDerEncoder.length; i++) {
     /* 378 */ arrayOfDerOutputStream[i] = new DerOutputStream();
     /* 379 */ paramArrayOfDerEncoder[i].derEncode(arrayOfDerOutputStream[i]);
     /*     */ }
   /*     */
   /* 383 */ byte[][] arrayOfByte = new byte[arrayOfDerOutputStream.length][];
   /* 384 */ for (int j = 0; j < arrayOfDerOutputStream.length; j++) {
     /* 385 */ arrayOfByte[j] = arrayOfDerOutputStream[j].toByteArray();
     /*     */ }
   /* 387 */ Arrays.sort(arrayOfByte, paramComparator);
   /*     */
   /* 389 */ DerOutputStream localDerOutputStream = new DerOutputStream();
   /* 390 */ for (int k = 0; k < arrayOfDerOutputStream.length; k++) {
     /* 391 */ localDerOutputStream.write(arrayOfByte[k]);
     /*     */ }
   /* 393 */ write(paramByte, localDerOutputStream);
   /*     */ }
 /**
  * Encodes a <code>PrincipalName</code> object. Note that only the type and names are encoded. To
  * encode the realm, call getRealm().asn1Encode().
  *
  * @return the byte array of the encoded PrncipalName object.
  * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
  * @exception IOException if an I/O error occurs while reading encoded data.
  */
 public byte[] asn1Encode() throws Asn1Exception, IOException {
   DerOutputStream bytes = new DerOutputStream();
   DerOutputStream temp = new DerOutputStream();
   BigInteger bint = BigInteger.valueOf(this.nameType);
   temp.putInteger(bint);
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
   temp = new DerOutputStream();
   DerValue der[] = new DerValue[nameStrings.length];
   for (int i = 0; i < nameStrings.length; i++) {
     der[i] = new KerberosString(nameStrings[i]).toDerValue();
   }
   temp.putSequence(der);
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
   temp = new DerOutputStream();
   temp.write(DerValue.tag_Sequence, bytes);
   return temp.toByteArray();
 }
示例#19
0
 /*     */ public byte[] asn1Encode() /*     */ throws Asn1Exception, IOException /*     */ {
   /* 104 */ DerOutputStream localDerOutputStream1 = new DerOutputStream();
   /* 105 */ DerOutputStream localDerOutputStream2 = new DerOutputStream();
   /* 106 */ localDerOutputStream1.write(
       DerValue.createTag((byte) -128, true, (byte) 0), this.pATimeStamp.asn1Encode());
   /* 107 */ if (this.pAUSec != null) {
     /* 108 */ localDerOutputStream2 = new DerOutputStream();
     /* 109 */ localDerOutputStream2.putInteger(BigInteger.valueOf(this.pAUSec.intValue()));
     /* 110 */ localDerOutputStream1.write(
         DerValue.createTag((byte) -128, true, (byte) 1), localDerOutputStream2);
     /*     */ }
   /* 112 */ localDerOutputStream2 = new DerOutputStream();
   /* 113 */ localDerOutputStream2.write((byte) 48, localDerOutputStream1);
   /* 114 */ return localDerOutputStream2.toByteArray();
   /*     */ }
 /*     */ public void encode(OutputStream paramOutputStream) /*     */ throws IOException
       /*     */ {
   /* 151 */ if ((this.notBefore == null) || (this.notAfter == null)) {
     /* 152 */ throw new IOException("CertAttrSet:CertificateValidity: null values to encode.\n");
     /*     */ }
   /*     */
   /* 155 */ DerOutputStream localDerOutputStream1 = new DerOutputStream();
   /*     */
   /* 157 */ if (this.notBefore.getTime() < 2524636800000L)
     /* 158 */ localDerOutputStream1.putUTCTime(this.notBefore);
   /*     */ else {
     /* 160 */ localDerOutputStream1.putGeneralizedTime(this.notBefore);
     /*     */ }
   /* 162 */ if (this.notAfter.getTime() < 2524636800000L)
     /* 163 */ localDerOutputStream1.putUTCTime(this.notAfter);
   /*     */ else {
     /* 165 */ localDerOutputStream1.putGeneralizedTime(this.notAfter);
     /*     */ }
   /* 167 */ DerOutputStream localDerOutputStream2 = new DerOutputStream();
   /* 168 */ localDerOutputStream2.write((byte) 48, localDerOutputStream1);
   /*     */
   /* 170 */ paramOutputStream.write(localDerOutputStream2.toByteArray());
   /*     */ }
示例#21
0
 /** Construct a key from its components. Used by the RSAKeyFactory and the RSAKeyPairGenerator. */
 RSAPrivateCrtKeyImpl(
     BigInteger n,
     BigInteger e,
     BigInteger d,
     BigInteger p,
     BigInteger q,
     BigInteger pe,
     BigInteger qe,
     BigInteger coeff)
     throws InvalidKeyException {
   this.n = n;
   this.e = e;
   this.d = d;
   this.p = p;
   this.q = q;
   this.pe = pe;
   this.qe = qe;
   this.coeff = coeff;
   RSAKeyFactory.checkRSAProviderKeyLengths(n.bitLength(), e);
   // generate the encoding
   algid = rsaId;
   try {
     DerOutputStream out = new DerOutputStream();
     out.putInteger(0); // version must be 0
     out.putInteger(n);
     out.putInteger(e);
     out.putInteger(d);
     out.putInteger(p);
     out.putInteger(q);
     out.putInteger(pe);
     out.putInteger(qe);
     out.putInteger(coeff);
     DerValue val = new DerValue(DerValue.tag_Sequence, out.toByteArray());
     key = val.toByteArray();
   } catch (IOException exc) {
     // should never occur
     throw new InvalidKeyException(exc);
   }
 }
 /*     */ public byte[] asn1Encode() /*     */ throws Asn1Exception, IOException /*     */ {
   /* 182 */ DerOutputStream localDerOutputStream1 = new DerOutputStream();
   /* 183 */ DerOutputStream localDerOutputStream2 = new DerOutputStream();
   /* 184 */ localDerOutputStream1.write(
       DerValue.createTag((byte) -128, true, (byte) 0), this.flags.asn1Encode());
   /*     */
   /* 186 */ localDerOutputStream1.write(
       DerValue.createTag((byte) -128, true, (byte) 1), this.key.asn1Encode());
   /*     */
   /* 188 */ localDerOutputStream1.write(
       DerValue.createTag((byte) -128, true, (byte) 2), this.crealm.asn1Encode());
   /*     */
   /* 190 */ localDerOutputStream1.write(
       DerValue.createTag((byte) -128, true, (byte) 3), this.cname.asn1Encode());
   /*     */
   /* 192 */ localDerOutputStream1.write(
       DerValue.createTag((byte) -128, true, (byte) 4), this.transited.asn1Encode());
   /*     */
   /* 194 */ localDerOutputStream1.write(
       DerValue.createTag((byte) -128, true, (byte) 5), this.authtime.asn1Encode());
   /*     */
   /* 196 */ if (this.starttime != null) {
     /* 197 */ localDerOutputStream1.write(
         DerValue.createTag((byte) -128, true, (byte) 6), this.starttime.asn1Encode());
     /*     */ }
   /*     */
   /* 200 */ localDerOutputStream1.write(
       DerValue.createTag((byte) -128, true, (byte) 7), this.endtime.asn1Encode());
   /*     */
   /* 203 */ if (this.renewTill != null) {
     /* 204 */ localDerOutputStream1.write(
         DerValue.createTag((byte) -128, true, (byte) 8), this.renewTill.asn1Encode());
     /*     */ }
   /*     */
   /* 208 */ if (this.caddr != null) {
     /* 209 */ localDerOutputStream1.write(
         DerValue.createTag((byte) -128, true, (byte) 9), this.caddr.asn1Encode());
     /*     */ }
   /*     */
   /* 213 */ if (this.authorizationData != null) {
     /* 214 */ localDerOutputStream1.write(
         DerValue.createTag((byte) -128, true, (byte) 10), this.authorizationData.asn1Encode());
     /*     */ }
   /*     */
   /* 217 */ localDerOutputStream2.write((byte) 48, localDerOutputStream1);
   /* 218 */ localDerOutputStream1 = new DerOutputStream();
   /* 219 */ localDerOutputStream1.write(
       DerValue.createTag((byte) 64, true, (byte) 3), localDerOutputStream2);
   /*     */
   /* 221 */ return localDerOutputStream1.toByteArray();
   /*     */ }
示例#23
0
 /**
  * Encodes a Realm object.
  *
  * @return the byte array of encoded KrbCredInfo object.
  * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
  * @exception IOException if an I/O error occurs while reading encoded data.
  */
 public byte[] asn1Encode() throws Asn1Exception, IOException {
   DerOutputStream out = new DerOutputStream();
   out.putDerValue(new KerberosString(this.realm).toDerValue());
   return out.toByteArray();
 }
示例#24
0
  /** Get the encoding of the key. */
  public synchronized byte[] getEncoded() {
    if (this.encodedKey == null) {
      try {
        DerOutputStream algid = new DerOutputStream();

        // store oid in algid
        algid.putOID(new ObjectIdentifier(DH_data));

        // encode parameters
        DerOutputStream params = new DerOutputStream();
        params.putInteger(this.p);
        params.putInteger(this.g);
        if (this.l != 0) params.putInteger(this.l);
        // wrap parameters into SEQUENCE
        DerValue paramSequence = new DerValue(DerValue.tag_Sequence, params.toByteArray());
        // store parameter SEQUENCE in algid
        algid.putDerValue(paramSequence);

        // wrap algid into SEQUENCE, and store it in key encoding
        DerOutputStream tmpDerKey = new DerOutputStream();
        tmpDerKey.write(DerValue.tag_Sequence, algid);

        // store key data
        tmpDerKey.putBitString(this.key);

        // wrap algid and key into SEQUENCE
        DerOutputStream derKey = new DerOutputStream();
        derKey.write(DerValue.tag_Sequence, tmpDerKey);
        this.encodedKey = derKey.toByteArray();
      } catch (IOException e) {
        return null;
      }
    }
    return (byte[]) this.encodedKey.clone();
  }
示例#25
0
  public static void main(String[] args) throws Exception {

    s = new String("This is just a test!");

    byte[] asciiBytes = s.getBytes("ASCII");
    byte[] utf8Bytes = s.getBytes("UTF8");
    byte[] iso8859_1Bytes = s.getBytes("ISO-8859-1");

    byte[] unicodeBytes = s.getBytes("UnicodeBigUnmarked");
    byte[] unicodeBytes2 = getBytes(s);

    // test that unicode encoder is the correct one
    if (!equalBytes(unicodeBytes, unicodeBytes2))
      throw new Exception("Problem with unicode encoder being used.");

    FileOutputStream fout = new FileOutputStream(fileName);
    DerOutputStream derOut = new DerOutputStream();

    System.out.println("Writing Java string out as various DER" + " encoded Strings now...");
    derOut.putUTF8String(s);
    derOut.putPrintableString(s);
    derOut.putIA5String(s);
    derOut.putT61String(s);
    derOut.putBMPString(s);

    derOut.derEncode(fout);
    fout.close();

    FileInputStream fis = new FileInputStream(fileName);
    byte[] data = new byte[fis.available()];
    fis.read(data);
    DerInputStream derIn = new DerInputStream(data);
    fis.close();

    System.out.println("\nReading Strings back as DerValue's...\n");

    DerValue der;

    der = derIn.getDerValue();
    verifyDER("UTF8", der, DerValue.tag_UTF8String, utf8Bytes);

    der = derIn.getDerValue();
    verifyDER("Printable", der, DerValue.tag_PrintableString, asciiBytes);

    der = derIn.getDerValue();
    verifyDER("IA5", der, DerValue.tag_IA5String, asciiBytes);

    der = derIn.getDerValue();
    verifyDER("T61", der, DerValue.tag_T61String, iso8859_1Bytes);

    der = derIn.getDerValue();
    verifyDER("BMP", der, DerValue.tag_BMPString, unicodeBytes);

    if (derIn.available() > 0) throw new Exception("DerInputStream has extra data!");

    derIn.reset();

    System.out.println("Reading Strings back as Strings...\n");

    verifyString("UTF8", derIn.getUTF8String());
    verifyString("Printable", derIn.getPrintableString());
    verifyString("IA5", derIn.getIA5String());
    verifyString("T61", derIn.getT61String());
    verifyString("BMP", derIn.getBMPString());
  }
示例#26
0
  /**
   * Encodes an EncTicketPart object.
   *
   * @return byte array of encoded EncTicketPart object.
   * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
   * @exception IOException if an I/O error occurs while reading encoded data.
   */
  public byte[] asn1Encode() throws Asn1Exception, IOException {
    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), flags.asn1Encode());
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), key.asn1Encode());
    bytes.write(
        DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), cname.getRealm().asn1Encode());
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), cname.asn1Encode());
    bytes.write(
        DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x04), transited.asn1Encode());
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x05), authtime.asn1Encode());
    if (starttime != null) {
      bytes.write(
          DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x06), starttime.asn1Encode());
    }
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x07), endtime.asn1Encode());

    if (renewTill != null) {
      bytes.write(
          DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x08), renewTill.asn1Encode());
    }

    if (caddr != null) {
      bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x09), caddr.asn1Encode());
    }

    if (authorizationData != null) {
      bytes.write(
          DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x0A),
          authorizationData.asn1Encode());
    }
    temp.write(DerValue.tag_Sequence, bytes);
    bytes = new DerOutputStream();
    bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x03), temp);
    return bytes.toByteArray();
  }