Encrypt or Decrypt your password

Ranjeet_8
Posted by Ranjeet_8 under ASP.NET category on | Points: 40 | Views : 2737

using System.Security.Cryptography;

Encrypt Your Password :

public string Encrypt_Data(string Msg)
{
string key = "RaNjEeT";

byte[] Results;
System.Text.UTF8Encoding UTF8_Code = new System.Text.UTF8Encoding();
MD5CryptoServiceProvider HashMD5Provider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashMD5Provider.ComputeHash(UTF8_Code.GetBytes(key));
TripleDESCryptoServiceProvider TripleDESAlgorithm = new TripleDESCryptoServiceProvider();
TripleDESAlgorithm.Key = TDESKey;
TripleDESAlgorithm.Mode = CipherMode.ECB;
TripleDESAlgorithm.Padding = PaddingMode.PKCS7;
byte[] DataToEncrypt = UTF8_Code.GetBytes(Msg);
try
{
ICryptoTransform Encryptor = TripleDESAlgorithm.CreateEncryptor();
Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length);
}
catch { return null; }
finally
{
TripleDESAlgorithm.Clear();
HashMD5Provider.Clear();
}
return Convert.ToBase64String(Results);
}

Decrypt Your Password :

public string Decrypt_Data(string Msg)
{
string key = "RaNjEeT";

byte[] Results;
byte[] DecryptData = Convert.FromBase64String(Msg);
System.Text.UTF8Encoding UTF8_Code = new System.Text.UTF8Encoding();
MD5CryptoServiceProvider HashMD5Provider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashMD5Provider.ComputeHash(UTF8_Code.GetBytes(key));
TripleDESCryptoServiceProvider TripleDESAlgorithm = new TripleDESCryptoServiceProvider();
TripleDESAlgorithm.Key = TDESKey;
TripleDESAlgorithm.Mode = CipherMode.ECB;
TripleDESAlgorithm.Padding = PaddingMode.PKCS7;
try
{
ICryptoTransform Decryptor = TripleDESAlgorithm.CreateDecryptor();
Results = Decryptor.TransformFinalBlock(DecryptData, 0, DecryptData.Length);
}
catch { return null; }
finally
{
TripleDESAlgorithm.Clear();
HashMD5Provider.Clear();
}
return UTF8_Code.GetString(Results);
}

Comments or Responses

Posted by: T.Saravanan on: 9/1/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi Ranjeet,

Could you explain little bit about your code?

Login to post response