public Template() {
   seqt = new SEQUENCE.Template();
   seqt.addElement(CertificationRequestInfo.getTemplate());
   // seqt.addElement( new ANY.Template() );
   seqt.addElement(AlgorithmIdentifier.getTemplate());
   seqt.addElement(BIT_STRING.getTemplate());
 }
  public static void main(String argv[]) {

    try {

      if (argv.length > 2 || argv.length < 1) {
        System.out.println("Usage: CertificationRequest <dbdir> [<certfile>]");
        System.exit(0);
      }

      CryptoManager.initialize(argv[0]);
      CryptoManager cm = CryptoManager.getInstance();

      // read in a cert
      BufferedInputStream bis = new BufferedInputStream(new FileInputStream(argv[1]));

      CertificationRequest cert =
          (CertificationRequest) CertificationRequest.getTemplate().decode(bis);

      CertificationRequestInfo info = cert.getInfo();

      info.print(System.out);

      // X509CertificationRequest hardcore = cm.findCertByNickname("Hardcore");
      // PublicKey key = hardcore.getPublicKey();

      cert.verify();
      System.out.println("verified");

      FileOutputStream fos = new FileOutputStream("certinfo.der");
      info.encode(fos);
      fos.close();

      // make a new public key
      CryptoToken token = cm.getInternalKeyStorageToken();
      KeyPairGenerator kpg = token.getKeyPairGenerator(KeyPairAlgorithm.RSA);
      kpg.initialize(512);
      System.out.println("Generating a new key pair...");
      KeyPair kp = kpg.genKeyPair();
      System.out.println("Generated key pair");

      // set the CertificationRequest's public key
      info.setSubjectPublicKeyInfo(kp.getPublic());

      // make new Name
      Name name = new Name();
      name.addCommonName("asldkj");
      name.addCountryName("US");
      name.addOrganizationName("Some Corp");
      name.addOrganizationalUnitName("Some Org Unit");
      name.addLocalityName("Silicon Valley");
      name.addStateOrProvinceName("California");
      info.setSubject(name);

      System.out.println("About to create a new cert request...");
      // create a new cert requestfrom this certReqinfo
      CertificationRequest genCert =
          new CertificationRequest(
              info, kp.getPrivate(), SignatureAlgorithm.RSASignatureWithMD5Digest);
      System.out.println("Created new cert request");

      genCert.verify();
      System.out.println("Cert verifies!");

      fos = new FileOutputStream("gencert.der");
      genCert.encode(fos);
      fos.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 /**
  * Verifies the signature on this CertificationRequest. Does not indicate that the
  * CertificationRequest is valid at any specific time.
  */
 public void verify()
     throws InvalidKeyException, CryptoManager.NotInitializedException, NoSuchAlgorithmException,
         CertificateException, TokenException, SignatureException, InvalidKeyFormatException {
   verify(info.getSubjectPublicKeyInfo().toPublicKey());
 }