0

I have the following property:

    [JsonProperty("Comments__c")]
    public string Comments__c { get; set; }

And sometimes sentitive information, specifically passwords, come in the value, like:

... ,"Comments__c":"30/07/19 - John Doe : www.site.com\r\n\r\nUser ID: user\r\nPassword: MrqRXgUXXIF4S2FkEWNvvcA",...

So, I need to edit anyway the value in the serialization, so when we have the word Password: it replaces everything ahead for XXXXXXX like:

... ,"Comments__c":"30/07/19 - John Doe : www.site.com\r\n\r\nUser ID: user\r\nPassword: XXXXXXX",...

I was checking the Newtonsoft Json Classes, but didn't find anything helpfuls, maybe I have to do it in the serialization?

Any insights will be greatly appreciated. Thanks!

  • Hum: storing a plain-text password in a comment field doesn't seem like such a good idea anyway – Charlieface Dec 27 '21 at 13:44
  • You would need to apply a custom `JsonConverter`. See e.g. [running a transformation on a Json DeserializeObject for a property](https://stackoverflow.com/q/38351661/3744182) or [How can I encrypt selected properties when serializing my objects?](https://stackoverflow.com/q/29196809/3744182). Do those two questions answer yours also, or do you need more specific help? – dbc Dec 27 '21 at 14:12

1 Answers1

0

Newtonsoft Json API extends dozens of various extension points to attach your logic there. So far your situation looks like a need in custom converter evaluating a string content and mutating it if there is a match: create custom json converter that masks sensitive information

https://www.newtonsoft.com/json/help/html/CustomJsonConverter.htm

Yury Schkatula
  • 5,291
  • 2
  • 18
  • 42