Ejemplo n.º 1
0
        void Decrypt(WireEncryptedString encryptedValue)
        {
            if (encryptedValue.EncryptedValue == null)
                throw new InvalidOperationException("Encrypted property is missing encryption data");

            encryptedValue.Value = EncryptionService.Decrypt(encryptedValue.EncryptedValue);
        }
Ejemplo n.º 2
0
        void Decrypt(WireEncryptedString encryptedValue)
        {
            if (encryptedValue.EncryptedValue == null)
            {
                throw new InvalidOperationException("Encrypted property is missing encryption data");
            }

            encryptedValue.Value = EncryptionService.Decrypt(encryptedValue.EncryptedValue);
        }
Ejemplo n.º 3
0
        void Decrypt(WireEncryptedString encryptedValue)
        {
            if (encryptedValue.EncryptedValue == null)
            {
                throw new Exception("Encrypted property is missing encryption data");
            }

            encryptedValue.Value = Decrypt(encryptedValue.EncryptedValue);
        }
Ejemplo n.º 4
0
        public void TestHandler()
        {
            Test.Initialize();

            var dataId = Guid.NewGuid();
            var str    = "hello";
            WireEncryptedString secret = "secret";

            Test.Handler <RequestDataMessageHandler>()
            .SetIncomingHeader("Test", "abc")
            .ExpectReply <DataResponseMessage>(m => m.DataId == dataId && m.String == str)
            .OnMessage <RequestDataMessage>(m => { m.DataId = dataId; m.String = str; });
        }
        public void Should_throw_an_exception()
        {
            var svc = new FakeEncryptionService(new EncryptedValue
            {
                EncryptedBase64Value = "EncryptedBase64Value",
                Base64Iv = "Base64Iv"
            });

            var value = new WireEncryptedString
            {
                Value = "The real value"
            };

            // ReSharper disable once InvokeAsExtensionMethod
            var exception = Assert.Throws<Exception>(() => WireEncryptedStringConversions.DecryptValue(svc, value, null));
            Assert.AreEqual("Encrypted property is missing encryption data", exception.Message);
        }
        public void Should_throw_an_exception()
        {
            var svc = new FakeEncryptionService(new EncryptedValue
            {
                EncryptedBase64Value = "EncryptedBase64Value",
                Base64Iv             = "Base64Iv"
            });

            var value = new WireEncryptedString
            {
                Value = "The real value"
            };

            // ReSharper disable once InvokeAsExtensionMethod
            var exception = Assert.Throws <Exception>(() => WireEncryptedStringConversions.DecryptValue(svc, value, null));

            Assert.AreEqual("Encrypted property is missing encryption data", exception.Message);
        }
        public void BaseSetUp()
        {
            FakeEncryptedValue = new EncryptedValue
            {
                EncryptedBase64Value = EncryptedBase64Value,
                Base64Iv             = "init_vector"
            };

            FakeEncryptedString = new WireEncryptedString {
                EncryptedValue = FakeEncryptedValue
            };
            mutator = new EncryptionMessageMutator
            {
                EncryptionService = new FakeEncryptionService(FakeEncryptedValue)
            };

            MessageConventionExtensions.IsEncryptedPropertyAction = property => typeof(WireEncryptedString).IsAssignableFrom(property.PropertyType);
        }
 void EncryptWireEncryptedString(WireEncryptedString wireEncryptedString)
 {
     wireEncryptedString.EncryptedValue = EncryptionService.Encrypt(wireEncryptedString.Value);
     wireEncryptedString.Value = null;
 }
 void Decrypt(WireEncryptedString encryptedValue)
 {
     encryptedValue.Value = EncryptionService.Decrypt(encryptedValue.EncryptedValue);
 }
Ejemplo n.º 10
0
        void Decrypt(WireEncryptedString encryptedValue)
        {
            if (encryptedValue.EncryptedValue == null)
            {
                throw new Exception("Encrypted property is missing encryption data");
            }

            encryptedValue.Value = encryptionService.Decrypt(encryptedValue.EncryptedValue);
        }
        private object GetObjectOfTypeFromNode(Type t, XmlNode node)
        {
            if (t.IsSimpleType())
            {
                return(GetPropertyValue(t, node));
            }

            if (t == typeof(WireEncryptedString))
            {
                if (EncryptionService != null)
                {
                    var encrypted = GetObjectOfTypeFromNode(typeof(EncryptedValue), node) as EncryptedValue;
                    var s         = EncryptionService.Decrypt(encrypted);

                    return(new WireEncryptedString {
                        Value = s
                    });
                }

                foreach (XmlNode n in node.ChildNodes)
                {
                    if (n.Name.ToLower() == "encryptedbase64value")
                    {
                        var wes = new WireEncryptedString();
                        wes.Value = GetPropertyValue(typeof(String), n) as string;

                        return(wes);
                    }
                }
            }

            if (typeof(IEnumerable).IsAssignableFrom(t))
            {
                return(GetPropertyValue(t, node));
            }

            object result = MessageMapper.CreateInstance(t);

            foreach (XmlNode n in node.ChildNodes)
            {
                Type type = null;
                if (n.Name.Contains(":"))
                {
                    type = Type.GetType("System." + n.Name.Substring(0, n.Name.IndexOf(":")), false, true);
                }

                var prop = GetProperty(t, n.Name);
                if (prop != null)
                {
                    var val = GetPropertyValue(type ?? prop.PropertyType, n);
                    if (val != null)
                    {
                        propertyInfoToLateBoundPropertySet[prop].Invoke(result, val);
                        continue;
                    }
                }

                var field = GetField(t, n.Name);
                if (field != null)
                {
                    object val = GetPropertyValue(type ?? field.FieldType, n);
                    if (val != null)
                    {
                        fieldInfoToLateBoundFieldSet[field].Invoke(result, val);
                        continue;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 12
0
        private object GetObjectOfTypeFromNode(Type t, XmlNode node)
        {
            if (t.IsSimpleType())
                return GetPropertyValue(t, node);

            if (t == typeof(WireEncryptedString))
            {
                if (EncryptionService != null)
                {
                    var encrypted = GetObjectOfTypeFromNode(typeof (EncryptedValue), node) as EncryptedValue;
                    var s = EncryptionService.Decrypt(encrypted);

                    return new WireEncryptedString {Value = s};
                }

                foreach (XmlNode n in node.ChildNodes)
                    if (n.Name.ToLower() == "encryptedbase64value")
                    {
                        var wes = new WireEncryptedString();
                        wes.Value = GetPropertyValue(typeof (String), n) as string;

                        return wes;
                    }

            }

            if (typeof(IEnumerable).IsAssignableFrom(t))
                return GetPropertyValue(t, node);

            object result = MessageMapper.CreateInstance(t);

            foreach (XmlNode n in node.ChildNodes)
            {
                Type type = null;
                if (n.Name.Contains(":"))
                    type = Type.GetType("System." + n.Name.Substring(0, n.Name.IndexOf(":")), false, true);

                var prop = GetProperty(t, n.Name);
                if (prop != null)
                {
                    var val = GetPropertyValue(type ?? prop.PropertyType, n);
                    if (val != null)
                    {
                        propertyInfoToLateBoundPropertySet[prop].Invoke(result, val);
                        continue;
                    }
                }

                var field = GetField(t, n.Name);
                if (field != null)
                {
                    object val = GetPropertyValue(type ?? field.FieldType, n);
                    if (val != null)
                    {
                        fieldInfoToLateBoundFieldSet[field].Invoke(result, val);
                        continue;
                    }
                }
            }

            return result;
        }
Ejemplo n.º 13
0
 void EncryptWireEncryptedString(WireEncryptedString wireEncryptedString)
 {
     wireEncryptedString.EncryptedValue = Encrypt(wireEncryptedString.Value);
     wireEncryptedString.Value          = null;
 }
Ejemplo n.º 14
0
 void Decrypt(WireEncryptedString encryptedValue)
 {
     encryptedValue.Value = EncryptionService.Decrypt(encryptedValue.EncryptedValue);
 }
Ejemplo n.º 15
0
 public SecureMessageWithProtectedSetter(WireEncryptedString secret)
 {
     Secret = secret;
 }
Ejemplo n.º 16
0
 public SecureMessageWithProtectedSetter(WireEncryptedString secret)
 {
     Secret = secret;
 }
Ejemplo n.º 17
0
 void EncryptWireEncryptedString(WireEncryptedString wireEncryptedString)
 {
     wireEncryptedString.EncryptedValue = encryptionService.Encrypt(wireEncryptedString.Value);
     wireEncryptedString.Value          = null;
 }