I want to clear "immutable" string contents!
From: cppdev (cppdev9_at_yahoo.com)
Date: 08/19/03
- Next message: Jens Süßmeyer: "Re: Not associated with a trusted SQL Server connection"
- Previous message: Eugene V. Bobukh [MS]: "Re: Cannot add CodeGroup to LocalIntranet_Zone"
- Next in thread: Ivan Medvedev [MS]: "Re: I want to clear "immutable" string contents!"
- Reply: Ivan Medvedev [MS]: "Re: I want to clear "immutable" string contents!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 19 Aug 2003 12:00:37 -0700
Hi All!
I want to clear the string contents from sensitive information
such as passwords.
It's always the case that password will appear as string at some point
or another. And i feel uneasy leaving it hanging in memory indefinitely
(especially in case when string is Interned).
So at least for the case when string is not interned can we do:
string pass = Console.ReadLine();
if (string.IsInterned(pass) == null)
{
unsafe
{
fixed(void* pv = pass)
{
char* pb = (char*)pv;
for(int i =0; i < pass.Length; ++i)
pb[i] = '0';
}
}
}
Console.WriteLine(pass);
Note: explicit RuntimeHelpers.OffsetToStringData is not needed.
What do you all think about this? It does appear to work!
- Next message: Jens Süßmeyer: "Re: Not associated with a trusted SQL Server connection"
- Previous message: Eugene V. Bobukh [MS]: "Re: Cannot add CodeGroup to LocalIntranet_Zone"
- Next in thread: Ivan Medvedev [MS]: "Re: I want to clear "immutable" string contents!"
- Reply: Ivan Medvedev [MS]: "Re: I want to clear "immutable" string contents!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|