Implementing Simple Encryption and Decryption with ProtectedData ClassprotecteddataDemonstrates how to implement simple encryption and decryption of data such as database strings with the new ProtectedData class.C# .Net Fun - http://www.dotnetfun.com - Michael G.strDBStringSystem.StringThe database string to encrypt."Data Source=localhost; User ID=sa; Password=somepassword;"strFileNameSystem.StringThe file name to which encrypted data is saved and read from during decryption."ENCDBSTR.bin"
0)
{
// Decrypt/unprotect the DB string:
byte[] arrUnencryptedDBString = ProtectedData.Unprotect(arrEncryptedDBString,
arrEntropy, DataProtectionScope.CurrentUser);
// Convert the byte array to a string:
strUnencryptedDBString = System.Text.Encoding.Unicode.GetString(arrUnencryptedDBString);
}
// Return the unencrypted DB string:
return strUnencryptedDBString;
}
]]>