public static string Decrypt(EncryptionResult x) { var iv = Convert.FromBase64String(x.IV); var encrypted = Convert.FromBase64String(x.Encrypted); return(DecryptStringFromBytes_Aes(encrypted, x.Key, iv)); }
private static void Decrypt <T>(T poco) where T : IEncrypt { var properties = poco.GetType().GetProperties(); foreach (var property in properties) { var dto = ValidateEncryptPocoProperty(poco, property); if (dto.Exception != null) { throw dto.Exception; } if (dto.Attribute != null) { var encrypted = (string)property.GetValue(poco); var iv = (string)dto.KeyProperty.GetValue(poco); if (!string.IsNullOrEmpty(encrypted) && !string.IsNullOrEmpty(iv)) { var aesResult = new EncryptionResult(encrypted, iv, poco.EKey); property.SetValue(poco, Aes.Decrypt(aesResult)); } } } }