DPAPI Encryption
The following code uses the Windows API CryptProtectData to encrypt the string strValue by using the logged-on user’s credentials as a key. The encrypted value is stored in the user’s personal application data directory with the name <strSettingName>.txt.
Settings.SaveEncrypted(strSettingName, strValue)
The next line of code uses the Windows API CryptUnprotectData to decrypt the setting stored in the file <strSettingName>.txt. The result is assigned to the string strValue:
strValue = Settings.LoadEncrypted(strSettingName)
Get Security for Microsoft® Visual Basic® .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.