public void CanGenerateValidKey()
        {
            var key = RijndaelEncryptionTransportDecorator.GenerateKeyBase64();

            var localInstance = new RijndaelEncryptionTransportDecorator(sender, receiver, key);

            var toSend = new TransportMessageToSend
            {
                Label   = Guid.NewGuid().ToString(),
                Headers = new Dictionary <string, object>
                {
                    { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }
                },
                Body = Guid.NewGuid().ToByteArray(),
            };

            localInstance.Send("test", toSend, new NoTransaction());

            var receivedTransportMessage = sender.SentMessage.ToReceivedTransportMessage();

            receiver.SetUpReceive(receivedTransportMessage);

            var receivedMessage = localInstance.ReceiveMessage(new NoTransaction());

            receivedMessage.Label.ShouldBe(toSend.Label);
            var expectedHeaders = toSend.Headers.Clone();

            receivedMessage.Headers.ShouldBe(expectedHeaders);
            receivedMessage.Body.ShouldBe(toSend.Body);
        }
        protected override void DoSetUp()
        {
            sender    = new Sender();
            receiver  = new Receiver();
            transport = new RijndaelEncryptionTransportDecorator(sender, receiver, KeyBase64);

            Console.WriteLine(RijndaelHelper.GenerateNewKey());
        }
        static void DoItEncrypted(TransportConfigurer configurer, string inputQueueName, string iv, string key, string errorQueueName)
        {
            if (string.IsNullOrEmpty(inputQueueName))
            {
                throw new ConfigurationErrorsException("You need to specify an input queue.");
            }

            var msmqMessageQueue = new MsmqMessageQueue(inputQueueName, errorQueueName);
            var encryptionFilter = new RijndaelEncryptionTransportDecorator(msmqMessageQueue, msmqMessageQueue, iv, key);

            configurer.UseSender(encryptionFilter);
            configurer.UseReceiver(encryptionFilter);
        }
Пример #4
0
        static string GenerateRijndaelHelp()
        {
            return
                (string.Format(
                     @"To help you get started, here's a valid rijndael element, including a fresh and newly generated iv and
key - and yes, I promise that they have been generated just this moment :) you can try running your app
again if you don't believe me.

    <rijndael iv=""{0}"" key=""{1}""/>

The iv and key have been generated with the biggest valid sizes, so they ought to be pretty secure.
",
                     RijndaelEncryptionTransportDecorator.GenerateIvBase64(),
                     RijndaelEncryptionTransportDecorator.GenerateKeyBase64()));
        }
Пример #5
0
        static void DoItEncrypted(TransportConfigurer configurer, string inputQueueName, string iv, string key, string errorQueueName)
        {
            if (string.IsNullOrEmpty(inputQueueName))
            {
                throw new ConfigurationErrorsException("You need to specify an input queue.");
            }

            var msmqMessageQueue = new MsmqMessageQueue(inputQueueName);
            var encryptionFilter = new RijndaelEncryptionTransportDecorator(msmqMessageQueue, msmqMessageQueue, iv, key);

            var errorQueuePath = MsmqUtil.GetPath(errorQueueName);

            MsmqUtil.EnsureMessageQueueExists(errorQueuePath);
            MsmqUtil.EnsureMessageQueueIsTransactional(errorQueuePath);

            configurer.UseSender(encryptionFilter);
            configurer.UseReceiver(encryptionFilter);
            configurer.UseErrorTracker(new ErrorTracker(errorQueueName));
        }
Пример #6
0
        public void CanGenerateValidIvAndKey()
        {
            var iv  = RijndaelEncryptionTransportDecorator.GenerateIvBase64();
            var key = RijndaelEncryptionTransportDecorator.GenerateKeyBase64();

            var localInstance = new RijndaelEncryptionTransportDecorator(sender, receiver, iv, key);

            var toSend = new TransportMessageToSend
            {
                Label   = Guid.NewGuid().ToString(),
                Headers = new Dictionary <string, string>
                {
                    { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }
                },
                Body = Guid.NewGuid().ToByteArray(),
            };

            localInstance.Send("test", toSend);

            var sentMessage = sender.SentMessage;
            var receivedTransportMessage = new ReceivedTransportMessage
            {
                Id      = Guid.NewGuid().ToString(),
                Label   = sentMessage.Label,
                Headers = sentMessage.Headers,
                Body    = sentMessage.Body
            };

            receiver.SetUpReceive(receivedTransportMessage);

            var receivedMessage = localInstance.ReceiveMessage();

            receivedMessage.Label.ShouldBe(toSend.Label);
            var expectedHeaders = toSend.Headers.Clone();

            expectedHeaders[Headers.Encrypted] = null;
            receivedMessage.Headers.ShouldBe(expectedHeaders);
            receivedMessage.Body.ShouldBe(toSend.Body);
        }
Пример #7
0
 protected override void DoSetUp()
 {
     sender    = new Sender();
     receiver  = new Receiver();
     transport = new RijndaelEncryptionTransportDecorator(sender, receiver, InitializationVectorBase64, KeyBase64);
 }