/// <summary> /// Called during serialization to encrypt a property value /// </summary> public void SetValue(object target, object value) { string encryptedText = value as string; if (!string.IsNullOrEmpty(encryptedText)) { PropertyInfo.SetValue(target, DataProtection.Decrypt(encryptedText, Scope)); } }
/// <summary> /// Called during deserialization to decrypt a property value /// </summary> public object GetValue(object target) { string clearText = PropertyInfo.GetValue(target) as string; if (!string.IsNullOrEmpty(clearText)) { return(DataProtection.Encrypt(clearText, Scope)); } return(null); }
internal void OnDeserializedMethod(StreamingContext context) { try { string sourceString = DataProtection.Decrypt(SourceString, Scope); var keyPairs = sourceString.Split(PairSeparator); foreach (var kp in keyPairs) { string[] parts = kp.Split(KeyValueSeparator); if (parts.Length == 2) { Contents.Add(parts[0].Trim(), parts[1].Trim()); } } SourceString = null; } catch (Exception exc) { throw new Exception($"Error deserializing SecureDictionary: {exc.Message}", exc); } }
internal void OnSerializingMethod(StreamingContext context) { string sourceString = string.Join(PairSeparator.ToString(), this.Contents.Select(kp => $"{kp.Key}{KeyValueSeparator}{kp.Value}")); SourceString = DataProtection.Encrypt(sourceString, Scope); }