Implementing Simple Encryption and Decryption with ProtectedData Class protecteddata Demonstrates 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.
strDBString System.String The database string to encrypt. "Data Source=localhost; User ID=sa; Password=somepassword;" strFileName System.String The 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; } ]]>