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);
}
Slight improvement on Sascha's answer replacing the lambda with a method group
least amount of code because
.ToList()
is not required for this:Apart from using unsafe code and a
char*
, there isn't a (much) better way.The point here is not to copy SecureString contents to/from normal strings. The constant
"fizzbuzz"
constant is the security leak here.You could use Linq:
Since
SecureString
utilizes theIDispose
interface. You could actually do it like this.Essentially the
data
would be a parameter.If you utilize the
using
to help alleviate resources; you'll want to be careful about the scope. But this may be a beneficial alternative, depending on usage.Update:
You could actually do a full method signature:
For the decryption you would want to do:
The following article will give you some additional information as well.