A
A
Artem Voropaev2013-09-10 23:47:12
.NET
Artem Voropaev, 2013-09-10 23:47:12

SecureString, WinForms

It is given: WinForms, normal TextBox where the password is entered.
Question: How to correctly read data from this textbox into SecureString? Handle every keystroke from the keyboard in the testbox? Give an example, if not difficult.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
codecity, 2013-09-11
@Legolas

SecureString makes it harder to get the key by dumping your process's memory. We are talking about those keys that are constantly used by the application, for example, to access a third-party API (usually passwords do not apply to them, since the password is not stored in its pure form). If you store the key in a string or byte[], then it is easy to get it by creating a memory dump of the process and opening it in a regular text editor.
So whatever you need. It is best to save key information in a file, first encrypted with a password. After entering the password, there is no need to keep it in memory, just decrypt the file with access keys (and store the keys in SecureString).
If you really need to keep the password in memory (for example, to access the DBMS), then here is the simplest option :

var secure = new SecureString();
foreach (char c in textbox1.Text)
{
    secure.AppendChar(c);
}

But, as you understand, while the password entry form is open and until the garbage collector has cleared the Text value, the password data can be intercepted. After the form is closed, only the SecureString will remain, there is no clear password.
There are also more paranoid ways .

N
Nikolai Turnaviotov, 2013-09-11
@foxmuldercp

Have you read this?
1. social.msdn.microsoft.com/Forums/vstudio/en-US/69e82b78-08c5-4b37-85db-d270b1005ad5/how-to-set-mode-password-for-textbox-control
2. stackoverflow.com/questions /2555984/quick-question-how-to-set-a-text-box-for-inputing-password-in-winforms

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question