public void Decryptproperties(IEncryptableClass ob) { var _properties = ob.GetType().GetProperties(); foreach (var _property in _properties) { var _propertyAttribute = Attribute.GetCustomAttribute(_property, typeof(MustEncrypt)); if (_propertyAttribute != null) { if (_property.GetValue(ob) != null) { _property.SetValue(ob, AesDecrypt(_property.GetValue(ob).ToString())); } } } }
/// <summary> /// Encrypts the properties marked with MustEncrypt of a class which implements IEncryptableClass. /// </summary> /// <param name="ob">The ob.</param> /// <param name="EncryptKey">The encrypt key.</param> public static void EncryptProperties(this IEncryptableClass ob, string EncryptKey) { var _properties = ob.GetType().GetProperties(); foreach (var _property in _properties) { var _propertyAttribute = Attribute.GetCustomAttribute(_property, typeof(MustEncrypt)); if (_propertyAttribute != null) { if (_property.GetValue(ob) != null) { _property.SetValue(ob, AesEncrypt(_property.GetValue(ob).ToString(), EncryptKey)); } } } }