public string encrypt(string serializedQueryString)
{
byte[] buffer = Encoding.ASCII.GetBytes(serializedQueryString);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
des.Key = MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey));
des.IV = IV;
return Convert.ToBase64String(
des.CreateEncryptor().TransformFinalBlock(
buffer,
0,
buffer.Length
)
);
}
public string decrypt(string encryptedQueryString)
{
try
{
byte[] buffer = Convert.FromBase64String(encryptedQueryString);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
des.Key = MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey));
des.IV = IV;
return Encoding.ASCII.GetString(
des.CreateDecryptor().TransformFinalBlock(
buffer,
0,
buffer.Length
)
);
}
catch (CryptographicException)
{
throw new InvalidQueryStringException();
}
catch (FormatException)
{
throw new InvalidQueryStringException();
}
}
Information
Subscribe to:
Post Comments (Atom)
1 comments:
More about.....C# Encryption
Dov
Post a Comment