public static void DecryptValue(this IEncryptionService encryptionService, WireEncryptedString wireEncryptedString, IIncomingLogicalMessageContext context) { if (wireEncryptedString.EncryptedValue == null) { throw new Exception("Encrypted property is missing encryption data"); } wireEncryptedString.Value = encryptionService.Decrypt(wireEncryptedString.EncryptedValue, context); }
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; }
public static void EncryptValue(this IEncryptionService encryptionService, WireEncryptedString wireEncryptedString, IOutgoingLogicalMessageContext context) { wireEncryptedString.EncryptedValue = encryptionService.Encrypt(wireEncryptedString.Value, context); wireEncryptedString.Value = null; }