Package codec.pkcs8

Examples of codec.pkcs8.EncryptedPrivateKeyInfo


    return new SubjectPublicKeyInfo((PublicKey) key)
      .getAlgorithmIdentifier();
      }

      if (key instanceof PrivateKey) {
    return new PrivateKeyInfo((PrivateKey) key)
      .getAlgorithmIdentifier();
      }

      throw new IllegalArgumentException("Key type not supported!");
View Full Code Here


    // set the DH parameter for empherial and anon cipher suites
    serverContext.setDHParameter(dhparam);
   
    KeyAndCertificate kac;
    EncryptedPrivateKeyInfo epki;
    String password = getPassword("Certificate password");

    try {
      kac = new KeyAndCertificate(certDir + "/serverRSA1024.pem");
      epki = (EncryptedPrivateKeyInfo)kac.getPrivateKey();
      epki.decrypt(password);
      serverContext.setRSACertificate(kac.getCertificateChain(), (RSAPrivateKey)epki.getPrivateKeyInfo());
    } catch (Exception ex) {
      System.out.println("Unable to set RSA server certificate.");
      System.out.println("RSA cipher-suites can not be used. " + ex);
    }

    try {
        // set the DSA certificate/private key for DSA cipher suites
      kac = new KeyAndCertificate(certDir + "/serverDSA1024.pem");
      epki = (EncryptedPrivateKeyInfo)kac.getPrivateKey();
      epki.decrypt(password);
      serverContext.setDSACertificate(kac.getCertificateChain(), epki.getPrivateKeyInfo());
    } catch (Exception ex) {
      System.out.println("Unable to set DSA server certificate.");
      System.out.println("DSA cipher-suites can not be used. " + ex);
    }

    try {
        // set the DH certificate/private key for DH cipher suites
      kac = new KeyAndCertificate(certDir + "/serverDH1024.pem");
      epki = (EncryptedPrivateKeyInfo)kac.getPrivateKey();
      epki.decrypt(password);
      serverContext.setDHCertificate(kac.getCertificateChain(), epki.getPrivateKeyInfo());
    } catch (Exception ex) {
      System.out.println("Unable to set Diffie-Hellman server certificate.");
      System.out.println("Diffie-Hellman cipher-suites can not be used. " + ex);
    }
View Full Code Here

  /*
   * Prompt the user for the password, and decrypt the key
   */

  EncryptedPrivateKeyInfo epk =
      (EncryptedPrivateKeyInfo) kac.getPrivateKey();
  System.out.println("CaHandler Key: " + epk);
  String passwd = getPassword(cert);
  try {
      serverKey = epk.decrypt(passwd);
  } catch (Exception e) {  // stupid exceptions get thrown with bad keys
      System.out.println("Error decrypting key Server's key: " + e);
      return false;
  } finally {
      passwd = null// hide the password
View Full Code Here

      X509Certificate[] chain = new X509Certificate[1];
      chain[0] = cert;

      /* encrypt the key and save the cert */

      EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(
        (PrivateKeyInfo)kp.getPrivate());
      epki.encrypt(getPassword("Certificate password"),
        AlgorithmID.pbeWithMD5AndDES_CBC, null);
      new KeyAndCertificate(epki, chain).saveTo(args[0], ASN1.PEM);
  } catch (Exception e) {
      System.out.println("OOPS: " + e);
      e.printStackTrace();
View Full Code Here

TOP

Related Classes of codec.pkcs8.EncryptedPrivateKeyInfo

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.