Package com.drighetto.essai.bouncycastle.certificate

Examples of com.drighetto.essai.bouncycastle.certificate.CertificateGenerator


   *         11 mars 07<br>
   * @param args
   */
  @SuppressWarnings("boxing")
  public static void main(String[] args) {
    CertificateGenerator certGenerator = new CertificateGenerator();
    KeyStoreUtil keyStoreUtil = new KeyStoreUtil();

    /*
     * Sample : Create a ROOT and a NORMALIZE certificates and display their
     * informations
     */
    System.out.println("---[Bouncy Castle Sample]---");
    try {
      System.out.println("[Certificate Sample]");
      // Create the ROOT certificate
      System.out.print("Generate a ROOT certificate...");
      RootCertificateVO rootCertificateVO = certGenerator
          .createRootCertificate();
      X509Certificate rootCertificate = rootCertificateVO
          .getRootCertificate();
      System.out.println("OK");
      System.out.println("Certificate content :");
      System.out.println(rootCertificate.toString());
      System.out.print("Certificate is currently valid : ");
      try {
        rootCertificate.checkValidity();
        System.out.println("YES");
      } catch (CertificateExpiredException cee) {
        System.out.printf("NO : %s\n", cee.getMessage());
      } catch (CertificateNotYetValidException cnye) {
        System.out.printf("NO : %s\n", cnye.getMessage());
      }

      System.out.println("--");
      System.out.println("------");
      System.out.println("--");

      // Create the NORMALIZE certificate
      System.out.print("Generate a NORMALIZE certificate...");
      X509Certificate normalizeCertificate = certGenerator
          .createNormalizeCertificate(rootCertificateVO);
      System.out.println("OK");
      System.out.println("Certificate content :");
      System.out.println(normalizeCertificate.toString());
      System.out.print("Certificate is currently valid : ");
      try {
        normalizeCertificate.checkValidity();
        System.out.println("YES");
      } catch (CertificateExpiredException cee) {
        System.out.printf("NO : %s\n", cee.getMessage());
      } catch (CertificateNotYetValidException cnye) {
        System.out.printf("NO : %s\n", cnye.getMessage());
      }

      System.out.println("--");
      System.out.println("------");
      System.out.println("--");

      // Write certificates objects to files
      System.out.print("Write ROOT certificate object to a file...");
      certGenerator.writeToFile(rootCertificate,
          "RootCertificateTest.cer");
      System.out.println("OK");
      System.out.print("Write NORMALIZE certificate object to a file...");
      certGenerator.writeToFile(normalizeCertificate,
          "NormalizeCertificateTest.cer");
      System.out.println("OK");

      System.out.println("--");
      System.out.println("------");
View Full Code Here


      if (Security.getProperty("BC") == null) {
        Security.addProvider(new BouncyCastleProvider());
      }

      /* Generate a root and a normal certificate for this sample */
      CertificateGenerator certificateGenerator = new CertificateGenerator();
      RootCertificateVO rootCertificateInfo = certificateGenerator.createRootCertificate();
      CertificateVO certificateContainer = certificateGenerator.createNormalizeCertificate2(rootCertificateInfo);

      /*
       * Create a keystore of type "JKS" using the "SUN" security provider
       * because BouncyCastle do not support this type of keystore and
       * then store the normal certificate private key into it
View Full Code Here

TOP

Related Classes of com.drighetto.essai.bouncycastle.certificate.CertificateGenerator

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.