/// <summary> /// Encryptes the session key stored in the SessionKey property /// and saves the results in the EncryptedSessionKey property. /// </summary> /// <remarks>This method also calles EncodeSessionKey so that it /// does not have been called before calling EncryptSessionKey. /// <p></p> /// Please note: calling this function takes some time, because /// asymmetrical encryption takes some time! /// </remarks> /// <param name="pkpPacket">An PublicKeyPacket to which /// the sessionkey should be encrypted to.</param> public void EncryptSessionKey(PublicKeyPacket pkpPacket) { EncodeSessionKey(pkpPacket.KeyMaterial[0].bitCount()); AsymmetricCipher acCipher = new RSA(); switch (aaPublicAlgorithm) { case AsymAlgorithms.ElGama_Encrypt_Sign: case AsymAlgorithms.ElGamal_Encrypt_Only: acCipher = new ElGamal(); break; case AsymAlgorithms.RSA_Encrypt_Only: case AsymAlgorithms.RSA_Encrypt_Sign: acCipher = new RSA(); break; default: throw new System.Exception("The chosen public key algorithm is not yet implemented!"); } this.bIsUpdated = true; biEncryptedSessionKey = acCipher.Encrypt(new BigInteger(this.bEncodedSessionKey), pkpPacket); }