I have a PSCustomObject that I need to serialize on disk in JSON but one property needs to be obfuscated before being written and of course, deobfuscated when read later on.
I found that JavaScriptSerializer could do the trick when customized with a JavaScriptConverter (both ways, read and write), but all the examples I find are in C#, for example this very interesting thread
is it possible to write such a JavaScriptConverter in Powershell (maybe using a Class in place of the PSCustomObject)?
as a matter of example, let say that the PSCustomObject is @{Username:"foo";Password:"bar"}
and that I want the JSON file to be
{
"Username": "foo",
"Password": "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b83de0765b9a2a4088e073b1166fd67e0000000002000000000003660000c000000010000000790fcfe1dce43342e8d444757f46c8d50000000004800000a0000000100000002d0020ca9088b3d85b27f597847a3dc908000000ca11862bdb95757b140000002802e326a0041e039d8ff9c41ff46ec24c1f"
}
with Password
in the JSON file being the SecureString version of the original password
property. the need is for Windows Powershell 5.1 only, not powershell 6+