示例#1
0
 // 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
0
 public static string EncryptString(System.Security.SecureString input)
 {
     byte[] inArray = ProtectedData.Protect(System.Text.Encoding.Unicode.GetBytes(input.ToInsecureString()), SettingsProvider.entropy, DataProtectionScope.CurrentUser);
     return(System.Convert.ToBase64String(inArray));
 }
        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();
        }