Why you need to decrypt the password? Usually a salted hash of the password is stored and compared. If you encrypt/decrypt the password you have the password as plain text again and this is dangerous. The hash should be salted to avoid duplicated hash if the some users have the same passwords. For the salt you can take the user name.
HashAlgorithm hash = new SHA256Managed();
string password = "12345";
string salt = "UserName";
byte[] plainTextBytes = Encoding.UTF8.GetBytes(password);
byte[] hashBytes = hash.ComputeHash(plainTextBytes);
byte[] saltBytes = Encoding.UTF8.GetBytes(salt);
byte[] plainTextWithSaltBytes = new byte[plainTextBytes.Length + saltBytes.Length];
for (int i = 0; i < plainTextBytes.Length; i++)
{
plainTextWithSaltBytes[i] = plainTextBytes[i];
}
byte[] saltedHashBytes = hash.ComputeHash(plainTextWithSaltBytes);
string saltedHashValue = Convert.ToBase64String(saltedHashBytes);
You can calculate the salted hash of the password and store that within your file. During the authentication you calculate the hash from the user entries again and compare this hash with the stored password hash. Since it should be very difficult (its never impossible, always a matter of time) to get the plain text from a hash the password is protected from reading as plain text again.
Tip: Never store or send a password unencrypted. If you get a new password, encrypt is as soon as possible!
Ref: stackoverflow.com
Please refer:
How To: Encrypt and Decrypt string Using C#[
^]
How to encrypt and decrypt password in asp.net using C#?[
^]
Some CP Articles:
Simple encrypting and decrypting data in C#[
^]
Encrypt and Decrypt Data with C#[
^]
Encrypt/Decrypt String using DES in C#[
^]
Encryption and Decryption on the .NET Framework[
^]