Tuesday, November 11, 2008

Encrypting data in .NET

Encrypting:
using System.Security.Cryptography;
...
string password;
string encryptedPassword = Convert.ToBase64String(
ProtectedData.Protect(Encoding.UTF8.GetBytes(password), null,
DataProtectionScope.CurrentUser));
Decrypting:
using System.Security.Cryptography;
...
string encryptedPassword;
string password = Encoding.UTF8.GetString(ProtectedData.Unprotect(
Convert.FromBase64String(encryptedPassword), null,
DataProtectionScope.CurrentUser))

1 comment:

r4i said...

That code is really nice and i am looking for the same code from many days.thanks for sharing wonderful information and code with us.