Hi All!
I want to clear the string contents from sensitive information
such as passwords, and etc.
It's always a 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 leats for the case when string is not interned i propose:
string pass = Console.ReadLin e();
if (string.IsInter ned(pass) == null)
{
unsafe
{
fixed(void* pv = pass)
{
char* pb = (char*)pv;
for(int i =0; i<pass.Length; ++i)
pb[i] = '0';
}
}
}
Console.WriteLi ne(pass);
Note: explicit RuntimeHelpers. OffsetToStringD ata is not needed.
What do you all think about this? 6 2814
Hi,
Since you know that strings are immutable, you can't clear or modify them in
any way (in theory).
Why not use a char array instead to store your password chars? It is at your
own disposal to create the array and destroy it. A few chars won't take up
too much memory.
Edward
"cppdev" <cp*****@yahoo. com> wrote in message
news:fc******** *************** **@posting.goog le.com... Hi All!
I want to clear the string contents from sensitive information such as passwords, and etc.
It's always a 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 leats for the case when string is not interned i propose:
string pass = Console.ReadLin e(); if (string.IsInter ned(pass) == null) { unsafe { fixed(void* pv = pass) { char* pb = (char*)pv; for(int i =0; i<pass.Length; ++i) pb[i] = '0'; } } } Console.WriteLi ne(pass);
Note: explicit RuntimeHelpers. OffsetToStringD ata is not needed.
What do you all think about this?
Hi,
I would love to use byte[] or char[],
but it's not my choice. I'm using TextControl
to get information from the user in winform.
And it only has Text property.
"Edward Yang" <neo_in_matrix@ > wrote in message news:<OU******* *******@TK2MSFT NGP09.phx.gbl>. .. Hi,
Since you know that strings are immutable, you can't clear or modify them in any way (in theory).
Why not use a char array instead to store your password chars? It is at your own disposal to create the array and destroy it. A few chars won't take up too much memory.
Edward
"cppdev" <cp*****@yahoo. com> wrote in message news:fc******** *************** **@posting.goog le.com... Hi All!
I want to clear the string contents from sensitive information such as passwords, and etc.
It's always a 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 leats for the case when string is not interned i propose:
string pass = Console.ReadLin e(); if (string.IsInter ned(pass) == null) { unsafe { fixed(void* pv = pass) { char* pb = (char*)pv; for(int i =0; i<pass.Length; ++i) pb[i] = '0'; } } } Console.WriteLi ne(pass);
Note: explicit RuntimeHelpers. OffsetToStringD ata is not needed.
What do you all think about this?
Yes i can use GetWindowText myself, but i also use
PasswordDeriveB ytes to derive keys for encryption
from user password and that only takes a string.
"JD" <No@Where.com > wrote in message news:<#i******* *******@TK2MSFT NGP09.phx.gbl>. .. Could you create a password control that stores the text into a byte[] instead of a string so that the pass never gets interned?
- J
"cppdev" <cp*****@yahoo. com> wrote in message news:fc******** *************** ***@posting.goo gle.com... Hi,
I would love to use byte[] or char[], but it's not my choice. I'm using TextControl to get information from the user in winform. And it only has Text property.
"Edward Yang" <neo_in_matrix@ > wrote in message news:<OU******* *******@TK2MSFT NGP09.phx.gbl>. .. Hi,
Since you know that strings are immutable, you can't clear or modify them in any way (in theory).
Why not use a char array instead to store your password chars? It is at your own disposal to create the array and destroy it. A few chars won't take up too much memory.
Edward
"cppdev" <cp*****@yahoo. com> wrote in message news:fc******** *************** **@posting.goog le.com... > Hi All! > > I want to clear the string contents from sensitive information > such as passwords, and etc. > > It's always a 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 leats for the case when string is not interned i propose: > > string pass = Console.ReadLin e(); > if (string.IsInter ned(pass) == null) > { > unsafe > { > fixed(void* pv = pass) > { > char* pb = (char*)pv; > for(int i =0; i<pass.Length; ++i) > pb[i] = '0'; > } > } > } > Console.WriteLi ne(pass); > > Note: explicit RuntimeHelpers. OffsetToStringD ata is not needed. > > What do you all think about this?
If a common string is used over and over again, .NET
may "intern" it or make a single instance of it and
whenever you try to create a new instance of it, it'll
just return you the reference to the main, interned one.
I believe this happens during JIT. It recognizes common
strings and just makes one copy of them.
-c
"News VS.NET ( MS ILM )" <sq**********@h otmail.com> wrote in message
news:uL******** *****@TK2MSFTNG P10.phx.gbl... Excuse my now knowing What does interned mean here.??
"JD" <No@Where.com > wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Could you create a password control that stores the text into a
byte[] instead of a string so that the pass never gets interned?
- J
"cppdev" <cp*****@yahoo. com> wrote in message news:fc******** *************** ***@posting.goo gle.com... Hi,
I would love to use byte[] or char[], but it's not my choice. I'm using TextControl to get information from the user in winform. And it only has Text property.
"Edward Yang" <neo_in_matrix@ > wrote in message news:<OU******* *******@TK2MSFT NGP09.phx.gbl>. .. > Hi, > > Since you know that strings are immutable, you can't clear or
modify them in > any way (in theory). > > Why not use a char array instead to store your password chars?
It is at your > own disposal to create the array and destroy it. A few chars
won't take up > too much memory. > > Edward > > "cppdev" <cp*****@yahoo. com> wrote in message > news:fc******** *************** **@posting.goog le.com... > > Hi All! > > > > I want to clear the string contents from sensitive information > > such as passwords, and etc. > > > > It's always a 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 leats for the case when string is not interned i
propose: > > > > string pass = Console.ReadLin e(); > > if (string.IsInter ned(pass) == null) > > { > > unsafe > > { > > fixed(void* pv = pass) > > { > > char* pb = (char*)pv; > > for(int i =0; i<pass.Length; ++i) > > pb[i] = '0'; > > } > > } > > } > > Console.WriteLi ne(pass); > > > > Note: explicit RuntimeHelpers. OffsetToStringD ata is not
needed. > > > > What do you all think about this?
Chad
Thank you.
"Chad Myers" <cm****@N0.SP.A M.austin.rr.com > wrote in message
news:uO******** ******@TK2MSFTN GP09.phx.gbl... If a common string is used over and over again, .NET may "intern" it or make a single instance of it and whenever you try to create a new instance of it, it'll just return you the reference to the main, interned one.
I believe this happens during JIT. It recognizes common strings and just makes one copy of them.
-c
"News VS.NET ( MS ILM )" <sq**********@h otmail.com> wrote in message news:uL******** *****@TK2MSFTNG P10.phx.gbl... Excuse my now knowing What does interned mean here.??
"JD" <No@Where.com > wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Could you create a password control that stores the text into a byte[] instead of a string so that the pass never gets interned?
- J
"cppdev" <cp*****@yahoo. com> wrote in message news:fc******** *************** ***@posting.goo gle.com... > Hi, > > I would love to use byte[] or char[], > but it's not my choice. I'm using TextControl > to get information from the user in winform. > And it only has Text property. > > "Edward Yang" <neo_in_matrix@ > wrote in message news:<OU******* *******@TK2MSFT NGP09.phx.gbl>. .. > > Hi, > > > > Since you know that strings are immutable, you can't clear or modify them in > > any way (in theory). > > > > Why not use a char array instead to store your password chars? It is at your > > own disposal to create the array and destroy it. A few chars won't take up > > too much memory. > > > > Edward > > > > "cppdev" <cp*****@yahoo. com> wrote in message > > news:fc******** *************** **@posting.goog le.com... > > > Hi All! > > > > > > I want to clear the string contents from sensitive information > > > such as passwords, and etc. > > > > > > It's always a 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 leats for the case when string is not interned i propose: > > > > > > string pass = Console.ReadLin e(); > > > if (string.IsInter ned(pass) == null) > > > { > > > unsafe > > > { > > > fixed(void* pv = pass) > > > { > > > char* pb = (char*)pv; > > > for(int i =0; i<pass.Length; ++i) > > > pb[i] = '0'; > > > } > > > } > > > } > > > Console.WriteLi ne(pass); > > > > > > Note: explicit RuntimeHelpers. OffsetToStringD ata is not needed. > > > > > > What do you all think about this?
Chad Myers <cm****@N0.SP.A M.austin.rr.com > wrote: If a common string is used over and over again, .NET may "intern" it or make a single instance of it and whenever you try to create a new instance of it, it'll just return you the reference to the main, interned one.
I believe this happens during JIT. It recognizes common strings and just makes one copy of them.
Fortunately it's not nearly as heuristic as that. All string
literals/constants are interned, and any string which you call Intern
on is interned. I don't believe anything else will get interned. You
also don't get the interned copy whenever you create a string with
identical contents - it's only if you're using the same string literal
or if you specifically ask for the interned version.
If the JIT started interning other strings, you'd end up with a
possible memory leak.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tino Lange |
last post by:
Hi!
I identified a bottleneck in my programs.
I just want to "encrypt" data by easy xoring. Ok - that's no
encryption at all - I know. But it's hardly readable - and that's
enough :-) Just some quick obscurity.
It turns out not to be quick at all. I really didn't expect this to be
a bottleneck, but it takes quite some time.
|
by: cppdev |
last post by:
Hi All!
I want to clear the string contents from sensitive information
such as passwords, and etc.
It's always a 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 leats for the case when string is not...
|
by: Marty |
last post by:
Hi,
I would like to replace "\r\n" by "_" within a specific string.
I tried :
strMyString.Replace('\r', '_');
strMyString.Replace('\n', '_');
or
strMyString.Replace(System.Environment.NewLine, '_');
|
by: Hardy Wang |
last post by:
Hi all,
I know it is better to handle large string with a StringBuilder, but how
does StringBuilder class improve the performance in the background?
Thanks!
--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
|
by: Lonifasiko |
last post by:
Hi,
Just want to replace character at index 1 of a string with another
character. Just want to replace character at that position. I thought
Replace method would be overloaded with an index parameter with which
you can write wanted character at that position. But no, Replace
method only allows replacing one known character with another. The...
| |
by: cameljs18 |
last post by:
Converting a string variable into a string literal. How do I add the
@ character in front of the string?
I cannot add it when the string is created as it will affect other
parts of the program.
I have tried these but they do not work:
label1.text = @S
label1.text = "@" + S
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |