Ejemplo n.º 1
0
        public void DecryptEntity <TEntity>(TEntity entity, string key, string iv, Action <TEntity, string, string> decryptCallBack) where TEntity : class, IEncryptedEntity
        {
            var encryptedProperties = entity.GetType().GetProperties()
                                      .Where(p => p.GetCustomAttributes(typeof(PropertyEncrypted), true).Any(a => p.PropertyType == typeof(string)));

            foreach (var property in encryptedProperties)
            {
                var encryptedValue = property.GetValue(entity) as string;
                if (string.IsNullOrEmpty(encryptedValue))
                {
                    continue;
                }
                var value = _cryptoProvider.DecryptString(encryptedValue, entity.DecryptionPrivateKey, iv);
                decryptCallBack.Invoke(entity, property.Name, value);
            }
        }