私SecureString
はマイクロソフトのクラスに使用する必要があり、インターネットで次のコードを見つけました:
public static class SecureStringExt
{
public static SecureString ConvertToSecureString(this string password)
{
if (password == null)
throw new ArgumentNullException("password");
unsafe //Red highlighted line
{
fixed (char* passwordChars = password)
{
var securePassword = new SecureString(passwordChars, password.Length);
securePassword.MakeReadOnly();
return securePassword;
}
}
}
}
唯一の問題は、unsafe
キーワードがCannot use unsafe construct in safe context
. 残念ながら、私はなぜこれが起こっているのかを見つけることができませんでした...
注: 上記のコードは LINQPad で実行されますが、VS2013 (resharper を使用) では実行されません。