public UdpRawMessage Encrypt(ICipher cipher) { CheckDisposed(); using (var encryptor = cipher.CreateEncryptor()) { UdpRawMessage encryptedMessage = new UdpRawMessage(this.memoryStreamPool, (int)this.stream.Length); using (CryptoStream cryptoStream = new CryptoStream(new NonDisposableStream(encryptedMessage.BaseStream), encryptor, CryptoStreamMode.Write)) { this.stream.Position = 0; this.stream.CopyTo(cryptoStream); cryptoStream.FlushFinalBlock(); return(encryptedMessage); } } }