本文整理汇总了C#中System.Security.SecureString.ToInsecureString方法的典型用法代码示例。如果您正苦于以下问题:C# SecureString.ToInsecureString方法的具体用法?C# SecureString.ToInsecureString怎么用?C# SecureString.ToInsecureString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.SecureString
的用法示例。
在下文中一共展示了SecureString.ToInsecureString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncryptString
// TODO: is the use of securestring any good if we need to use string anyway?
public static string EncryptString(SecureString input)
{
byte[] encryptedData = ProtectedData.Protect(
Encoding.Unicode.GetBytes(input.ToInsecureString()),
Entropy,
DataProtectionScope.CurrentUser);
string encryptedString = Convert.ToBase64String(encryptedData);
Array.Clear(encryptedData, 0, encryptedData.Length);
return encryptedString;
}
示例2: AskSettings
void AskSettings()
{
var askForCredentials = new CredentialsDialog();
bool? result = askForCredentials.ShowDialog();
if ( result != null && result.Value )
{
_settings.IsEnabled = true;
_settings.Username = askForCredentials.Username.Text;
_password = askForCredentials.Password.SecurePassword;
byte[] encryptedPassword = ProtectedData.Protect(
Encoding.Unicode.GetBytes( _password.ToInsecureString() ),
Entropy,
DataProtectionScope.CurrentUser );
_settings.Password = Convert.ToBase64String( encryptedPassword );
}
else
{
_settings.IsEnabled = false;
}
_config.Save();
}