Package net.suberic.pooka

Examples of net.suberic.pooka.PookaEncryptionManager


        signKey = profile.getEncryptionKey(EncryptionManager.PGP, true);
        break;
      }
    }

    PookaEncryptionManager cryptoManager = Pooka.getCryptoManager();

    InternetAddress from = (InternetAddress) mm.getFrom()[0];

    // Find the keys to sign and encrypt the messages
    if(signKey == null && (cryptoType == SMIME_SIGN || cryptoType == SMIME_BOTH)){
      Key[] keys = cryptoManager.getPrivateKeysForAddress(from.getAddress(), EncryptionManager.SMIME,  true);
      if (keys == null || keys.length == 0) {
        // show dialog
        signKey = CryptoKeySelector.selectPrivateKey(Pooka.getProperty("Pooka.crypto.privateKey.forSign", "Select key to sign this message."), EncryptionManager.SMIME, true);
      } else {
        signKey = keys[0];
      }

      if (signKey == null) {
        throw new GeneralSecurityException("No signature key selected.");
      }
    }

    if(signKey == null &&  (cryptoType == PGP_SIGN || cryptoType == PGP_BOTH)){
      Key[] keys = cryptoManager.getPrivateKeysForAddress(from.getAddress(), EncryptionManager.PGP,  true);
      if (keys == null || keys.length == 0) {
        // show dialog
        signKey = CryptoKeySelector.selectPrivateKey(Pooka.getProperty("Pooka.crypto.privateKey.forSign", "Select key to sign this message."), EncryptionManager.PGP, true);

      } else {
        signKey = keys[0];
      }

      if (signKey == null) {
        throw new GeneralSecurityException("No signature key selected.");
      }
    }

    List encKeys = new LinkedList();

    //TODO: get the encKey from the available public keys
    if (cryptoType == SMIME_ENCRYPT || cryptoType == SMIME_BOTH || cryptoType == PGP_ENCRYPT || cryptoType == PGP_BOTH) {
      String type = (cryptoType == SMIME_ENCRYPT || cryptoType == SMIME_BOTH) ? EncryptionManager.SMIME : EncryptionManager.PGP;
      // Get the public key of the senders
      Address[] froms = mm.getFrom();
      for (int i = 0; i < froms.length; i++) {
        from = (InternetAddress) froms[i];
        Key[] keys = cryptoManager.getPublicKeys(from.getAddress(), type, false);
        if (keys != null && keys.length > 0) {
          encKeys.add(keys[0]);
        }
      }

      // Get the public key of the receivers
      Address[] receivers = mm.getAllRecipients();
      for (int i = 0; i < receivers.length; i++) {
        InternetAddress rec = (InternetAddress) receivers[i];
        Key[] keys = cryptoManager.getPublicKeys(rec.getAddress(), type, false);
        if (keys != null && keys.length > 0) {
          encKeys.add(keys[0]);
        } else {
          Key key = CryptoKeySelector.selectPublicKey(Pooka.getProperty("Pooka.crypto.publicKey.forEncrypt", "Select key to encrypt this message."), EncryptionManager.PGP, false);
          if (key != null)
View Full Code Here


              if (((EncryptionKey)sigKey).getType() != ((EncryptionKey)cryptoKey).getType()) {
              throw new MessagingException(Pooka.getProperty("error.NewMessage.differentEncryption", "Encryption and Signature Keys must be of same type (PGP or S/MIME)"));
              }
              }
      */
      PookaEncryptionManager cryptoManager = Pooka.getCryptoManager();

      if (getSignatureKey() != null) {
        mm = cryptoManager.signMessage(mm, null, sigKey);
      }

      if (cryptoKeys != null) {
        mm = cryptoManager.encryptMessage(mm,
                                          cryptoKeys);
      }

      return mm;
    }
View Full Code Here

TOP

Related Classes of net.suberic.pooka.PookaEncryptionManager

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.