views:

83

answers:

1

hi all, I am using Application settings in my c# project to save gmail username and password. Before saving the settings I am encrypting the plain text password. When I am restarting the app retrieving them is of course without any problem but the retrieved password is encrypted. What I want is to decrypt it back before binding back to the textbox The code generated by the designer is something like the follows:

this.tb_Gmail_Password.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::MyApp.Properties.Settings.Default, "GmailPassword", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

I don’t know if I am able to put my question properly. Plz feel free to kick me if I sound like speaking alien language. I will give more description as per your suggestion…

Regards, N10i.

--edit--

while saving the configuration i am using a custom function to encrypt the password i.e.

Properties.Settings.Default.GmailPassword = MyApp.EncPass(tb_Gmail_Password.Text);

can i use something similar like

this.tb_Gmail_Password.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::MyApp.Properties.Settings.Default, MyApp.DecPass("GmailPassword"), true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

i.e.

MyApp.DecPass("GmailPassword")
+1  A: 

You encrypt the configuration using DPAPI DpapiProtectedConfigurationProvider, and you decrypt it using the same at application start up, see Encrypting Configuration Information Using Protected Configuration.

Remus Rusanu
thanks for your reply i will look into DPAPI but is it possible to use something similar as i have mentioned in the edited post?thanks and regards,N10I
Neel
You can attach a delegate to the Setting.Default.OnSettingsLoaded and to Settings.Default.OnSettingsSaving to decrypt/encrypt your password on the fly, as is being loaded from/saved to the config file.
Remus Rusanu
can u plz. explain using a sample code. if will be a great help if u can!
Neel