#27 SAVE USR/PW (LOCAL) C#
I wanted to encrypt and decrypt the string as a readable string.Here is a very simple quick example in C# Visual Studio 2019 WinForms based on the methods used in this article. Using the DPAPI, the Data Protection Application Programmer’s Interface.
Right click project > properties > settings > Create a username
and password
setting.
Now you can leverage those settings you just created. Here I save the username
and password
but only encrypt the password
in it’s respectable value field in the user.config
file.
Example of the encrypted string in the user.config
file
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="utf-8"?> <configuration> <userSettings> <secure_password_store.Properties.Settings> <setting name="username" serializeAs="String"> <value>admin</value> </setting> <setting name="password" serializeAs="String"> <value>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAQpgaPYIUq064U3o6xXkQOQAAAAACAAAAAAAQZgAAAAEAACAAAABlQQ8OcONYBr9qUhH7NeKF8bZB6uCJa5uKhk97NdH93AAAAAAOgAAAAAIAACAAAAC7yQicDYV5DiNp0fHXVEDZ7IhOXOrsRUbcY0ziYYTlKSAAAACVDQ+ICHWooDDaUywJeUOV9sRg5c8q6/vizdq8WtPVbkAAAADciZskoSw3g6N9EpX/8FOv+FeExZFxsm03i8vYdDHUVmJvX33K03rqiYF2qzpYCaldQnRxFH9wH2ZEHeSRPeiG</value> </setting> </secure_password_store.Properties.Settings> </userSettings> </configuration> |