Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SecureString

Can this be simplified to a one liner? Feel free to completely rewrite it as long as secureString gets initialized properly.

SecureString secureString = new SecureString (); foreach (char c in "fizzbuzz".ToCharArray()) {     secureString.AppendChar (c); } 
like image 405
Todd Smith Avatar asked Mar 10 '10 20:03

Todd Smith


People also ask

What should I use instead of SecureString?

There is no alternative to the SecureString class. The 'alternative' Microsoft encourages is found here: The general approach of dealing with credentials is to avoid them and instead rely on other means to authenticate, such as certificates or Windows authentication.

Is SecureString secure?

And yes, SecureString has drawbacks and is not completely secure, there are ways to access to data, for example, injecting Hawkeye into the process is mentioned on MSDN as a way to extract the SecureString.

How secure is Convertfrom SecureString?

SecureString uses Windows' Data protection API. It is likely to be strong enough to be unbreakable in practical situations - save rubber hose cryptanalysis. There might be ways to protect data, if you explain in more a detail what you are trying to achieve.

What is a SecureString PowerShell?

In PowerShell, there are a number of cmdlets that work with something called a secure string. When you create a saved credential object, the password is stored as a secure string.


1 Answers

Just use NetworkCredential. It has the conversion logic built-in.

SecureString ss = new NetworkCredential("", "fizzbuzz").SecurePassword; 

As others have noted, all of these techniques strip the security benefits of SecureString, but in certain situations (such as unit tests) this may be acceptable.

Update:

As noted in the comments, NetworkCredential can also be used to convert a SecureString back to a string.

string s = new NetworkCredential("", ss).Password; 
like image 116
Kevin Avatar answered Sep 19 '22 18:09

Kevin