private byte[] EncryptMessage(Message mToBeEncrypted, ulong[] lTargetKeyIDs) { CompressedMessage cmMessage = new CompressedMessage(); cmMessage.Compress(mToBeEncrypted); TransportablePublicKey[] tpkSelectedKeys = new TransportablePublicKey[lTargetKeyIDs.Length]; for (int i=0; i<lTargetKeyIDs.Length; i++) tpkSelectedKeys[i] = pkrKeyRing.Find(lTargetKeyIDs[i], true); SymAlgorithms saAlgo = GetSymAlgorithmPreferences(tpkSelectedKeys); SymmetricallyEncryptedDataPacket sedpEncrypted = new SymmetricallyEncryptedDataPacket(); SymmetricAlgorithm saEncrypt = CipherHelper.CreateSymAlgorithm(saAlgo); saEncrypt.Mode = CipherMode.OpenPGP_CFB; saEncrypt.GenerateKey(); byte[] bKey = saEncrypt.Key; ESKSequence esksKeys = new ESKSequence(); esksKeys = CreateESKSequence(tpkSelectedKeys, AsymActions.Encrypt, saAlgo, bKey); ICryptoTransform ictEncryptor = saEncrypt.CreateEncryptor(); byte[] bMessage = cmMessage.GetEncoded(); byte[] bOutput = new byte[bMessage.Length]; ictEncryptor.TransformBlock(bMessage, 0, bMessage.Length, ref bOutput, 0); bKey.Initialize(); int iOutLength = (saEncrypt.BlockSize >> 3) + 2 + bMessage.Length; sedpEncrypted.Body = new byte[iOutLength]; Array.Copy(bOutput, 0, sedpEncrypted.Body, 0, iOutLength); byte[] bESK = esksKeys.GetEncoded(); byte[] bEncrypted = sedpEncrypted.Generate(); byte[] bReturn = new byte[bESK.Length + bEncrypted.Length]; bESK.CopyTo(bReturn, 0); bEncrypted.CopyTo(bReturn, bESK.Length); return bReturn; }
/// <summary> /// Compresses the given message into this compressed /// message. /// </summary> /// <param name="message">The message that is to be /// compressed.</param> /// <remarks>No remarks</remarks> public void Compress(Message message) { Compress(message.GetEncoded()); }