How to convert String
to SecureString
?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Here is a cheap linq trick.
There is also another way to convert between
SecureString
andString
.1. String to SecureString
2. SecureString to String
Here is the link
If you would like to compress the conversion of a
string
to aSecureString
into aLINQ
statement you can express it as follows:However, keep in mind that using
LINQ
does not improve the security of this solution. It suffers from the same flaw as any conversion fromstring
toSecureString
. As long as the originalstring
remains in memory the data is vulnerable.That being said, what the above statement can offer is keeping together the creation of the
SecureString
, its initialization with data and finally locking it from modification.I'm agree with Spence (+1), but if you're doing it for learning or testing pourposes, you can use a foreach in the string, appending each char to the securestring using the AppendChar method.
You can follow this: