public void Deserialize(IReceiveContext context) { _wrappedSerializer.Deserialize(context); IConsumeContext <EncryptedMessageEnvelope> encryptedContext; context.TryGetContext(out encryptedContext); if (encryptedContext == null) { throw new SerializationException("Could not deserialize message."); } byte[] cipherBytes = Convert.FromBase64String(encryptedContext.Message.CipheredMessage); byte[] iv = Convert.FromBase64String(encryptedContext.Message.Iv); var cipherStream = new EncryptedStream(cipherBytes, iv); using (ICryptographyService cryptographyService = new RijndaelCryptographyService(_key)) { Stream clearStream = cryptographyService.Decrypt(cipherStream); context.SetBodyStream(clearStream); _wrappedSerializer.Deserialize(context); } }
public object Deserialize(Stream input) { object message = _xmlSerializer.Deserialize(input); if (message == null) { throw new SerializationException("Could not deserialize message."); } if (message is EncryptedMessageEnvelope) { var envelope = message as EncryptedMessageEnvelope; var cipherBytes = Convert.FromBase64String(envelope.CipheredMessage); var iv = Convert.FromBase64String(envelope.Iv); var cipherStream = new EncryptedStream(cipherBytes, iv); using (ICryptographyService cryptographyService = new RijndaelCryptographyService(_key)) { var clearStream = cryptographyService.Decrypt(cipherStream); return(_xmlSerializer.Deserialize(clearStream)); } } return(message); }
public void Smoke() { EncryptedText result; using (ICryptographyService srv = new RijndaelCryptographyService(Key)) { result = srv.Encrypt(PlainText); } string decryptedText; using (ICryptographyService srv2 = new RijndaelCryptographyService(Key)) { decryptedText = srv2.Decrypt(result); } Assert.AreEqual(PlainText, decryptedText); }
public void Smoke_stream2() { var tryThese = new List <string> { "hear back from alumni and be informed as to how they are progressing in both their personal and professional lives. To feel like you have had a positive impact and were able to add value to someone's life is an awesome thing. I just received an email from a recent alumni who signed his email with the following:", @"<?xml version=""1.0"" encoding=""utf-8""?> <x:XmlMessageEnvelope xmlns:x=""MassTransit.Serialization.XmlMessageEnvelope, MassTransit, Version=0.5.0.1927, Culture=neutral, PublicKeyToken=null"" xmlns:m=""MassTransit.Serialization.EncryptedMessageEnvelope, MassTransit, Version=0.5.0.1927, Culture=neutral, PublicKeyToken=null"" xmlns:s=""System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" xmlns:i=""System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089""> <m:Message> <s:CipheredMessage>XJHSdnhCcmDH5bNlws03TXD72vP3pTwcwTYKbor+oMJtUVcUKmpHdzHQmHjS+ZGP6I4GAmGExznMXCZvT3zMldv4WDqPRX9tfTlGxsYXjpTnhuF87TFDp64dc5gGltwhLOHjvDsp05ExbGSNVh0yn8J5/ouKbxpaOVQHegIHAScgWbScI1ZKaue9JJ8R8KhejdO73VDYIRNlVJCe9vYwLK81zka2IV+6d+7GS4p/XLR0QoEwA+MXNacmQujPtaSnJ6o5Crqy98XBcRIfuqoNM+OTL3zIzOV9DcpMzs6KoxVsM6d0jZ8pJT7sDgRkcFjaufONTfNznJkfC2ytrNtw5kxCh5764tvcir+D/g1eOYB8gN3IM+dv2NSTVQr8i/jKddfnGo0cbE+HETt4ie5CQ3DlIzixLDeFTUIdgdE8gVb2h95EuxCKlWOxymoFPQ8DyYpBraS2ac7qndTTTr5bYDQkCfSm9i4oMBxkMRCIxsSi7mw3UxGHOW/3zvuMpPdfD4z63TuOJ5JW4L/Alq7IIWH2S6VieAT8TL+y7j/asu73dH8Ukcrd7FCRb9egvQvVyIV1z/Kfficeo2UC7gIZQ/ZjDSTLI6ARn+Lvg4mt513D/VJNsDeS28kgRstWLEskqg/rq4mPxbm45UevA10XhgTDXlcc14bD7r2AYSD8i/g6vM32OPyn0onCCm5KDBCtcXqah0OuzLyGqqxKooNMIDE/wNnumSq7geW+bOn925mlrOUR7Zl7sGgELyerGZ2bRtdP7NSmpuukWW8ROhBKpn7iAUPbE1YsItFo3ex5Mjk/dW4EQ1sbufYk9Y3AIumoveH1G68nJLnF18RosNoHRYJffInYw2ndOsb3R+Db6tiupl2IFWqc45TRBIBtUP0tuR/oo1kBt8HTDFKBCq2G2mw1o60Tm3sY7hlp21anJ2aGSZJGPIhXljKm8pg4D66GL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uIU8qOAxJDTPHu9FaHY/FK/sRhANHLPkYYpBv5vIJKo3QNtBon8+AEiOb5UT4Ho5PZmgt6VdnhNUhMabg0tonerw8x4u0QmgWlhfq9ZlgySjaEp/fA6YaxAC3hF7t+lYtMNxbUNr+scrIMy8tAY09GLjnw8yI2JZrq9LUM7MV/3c62wOtTO7Klm03NpKGrQUD1rXwVv+eeQL5Jgt+TfGx3/g3hNf0h9s6KjbTJhLEuA4O2VI8EQQ2AZ5wtGaxYXzkTAcs7/fQ6rXX42/liZsBQndBodUopolkaFhIbHlx02AR3YJq2jSAKwYr1nREmbiJ2uVCq7HruTGe+Iz0e1WlGGW9nf2wFV5mD4FMVpI3GBznfYg+lW6ZBZI8GaR1OhmDQjflqx8V+zrRsj+KyNMQR8ut47fvdpr0iVgpjCMqJJBLIigSXnf30BKFy0PKrmDRfDMGu0Mg8pwprMzPK8h4EFvgvOnhmVe0I3Ydfn0mHOmFaOu1t8nUbqHcDJxxE+qMnK3Jvt1jnuhYijSlHXbcOpvJZ3gQPoGkRzKUFVZvWZyj0t2bVSNoBJQGCvhQz3RNk5LKys287UJ38KyfdzH4AM9aakb8t4CLFzVeYflr1ShGP5w9MkRhw0rSUSzFJerEO2N51+G9WsBBNtmQ+ZnCsl+814JcwaJPCQtu8GQYgODF0Q3u4b/rZkFYzh7RiLcAMysGbbhlfh2QaHinrNZ1yhPbF/I7KsEk0lKMktu5SeKkD+w5kC9giBjYekyQec9s3btp0DGnHe1apMgD5IWIfxwl3nEPsXjR5RXrb241U6qPuJKj6NgIjjFCKvT/Z266bd1T15/+npgOzYfBwrLGk63pT7A5oBGosgsM6rjUAH0zAFfL6yhFcTJcb0p+Q2T/2UIYxwwj</s:CipheredMessage> <s:IV>5HeLBvGhHZ3ox8QSBJJ2/QrcPUL+s872LZfEp/Lofn4=</s:IV> </m:Message> <i:RetryCount>0</i:RetryCount> <s:MessageType>MassTransit.Serialization.EncryptedMessageEnvelope, MassTransit</s:MessageType> </x:XmlMessageEnvelope>", new string('z', 4000) }; foreach (var thing in tryThese) { _clearBytes = Encoding.UTF8.GetBytes(thing); var plainStrea = new MemoryStream(_clearBytes); EncryptedStream result; using (ICryptographyService srv = new RijndaelCryptographyService(Key)) { result = srv.Encrypt(plainStrea); } plainStrea.Position = 0; Stream decryptedStream; using (ICryptographyService srv2 = new RijndaelCryptographyService(Key)) { decryptedStream = srv2.Decrypt(result); } AssertStreams(plainStrea, decryptedStream); } }
public void Smoke_stream() { _clearBytes = Encoding.UTF8.GetBytes(PlainText); _clearStream = new MemoryStream(_clearBytes); EncryptedStream encryptionResult; using (ICryptographyService srv = new RijndaelCryptographyService(Key)) { encryptionResult = srv.Encrypt(_clearStream); } _clearStream.Position = 0; Stream decryptedStream; using (ICryptographyService srv2 = new RijndaelCryptographyService(Key)) { decryptedStream = srv2.Decrypt(encryptionResult); } AssertStreams(_clearStream, decryptedStream); }