I have a property that holds a personal information. I am trying to figure out the best approach to guard against any kind of Privacy Violation: Heap Inspection. This is what I have so far:
private static SecureString _testPI;
public static string TestPI
{
get
{
return ConvertToString(_testPI);
}
set
{
_testPI= ConvertToSecureString(value);
}
}
As you can see I have two methods ConvertToString
and ConvertToSecureString
. As the methods name points out they convert a string taken from the user or database and converts it to a SecureString, then converted back to a regular string when the property is called.
Also when the class is instantiated I do whatever I need to do with the class then set the instance to null
.
TestClass myTest = new TestClass();
myTest.TestPI= testString;
ValidatePI(myTest.TestPI);
myTest = null;
Is this best practice?
I am using .NET framework 4.5.1