string strResult;
byte[] KEY_192 = {42, 16, 93, 156, 78, 4, 218, 32,15, 167, 44, 80, 26, 250, 155, 112,2, 94, 11, 204, 119, 35, 184, 197};
byte[] IV_192 = {55, 103, 246, 79, 36, 99, 167, 3,42, 5, 62, 83, 184, 7, 209, 13,145, 23, 200, 58, 173, 10, 121, 222};
public string encrypt(string strInput)
{
TripleDESCryptoServiceProvider cryptoProvider=new TripleDESCryptoServiceProvider();
MemoryStream ms=new MemoryStream();
CryptoStream cs=new CryptoStream(ms,cryptoProvider.CreateEncryptor(KEY_192, IV_192),CryptoStreamMode.Write);
StreamWriter sw=new StreamWriter(cs);
sw.Write(strInput);
sw.Flush();
cs.Flush();
cs.FlushFinalBlock();
ms.Flush();
strResult=Convert.ToBase64String(ms.GetBuffer(),0,Convert.ToInt32(ms.Length));
return strResult;
}
public string decrypt(string strinput)
{
TripleDESCryptoServiceProvider cryptoProvider=new TripleDESCryptoServiceProvider();
byte[] buffer=Convert.FromBase64String(strinput.Trim());
MemoryStream ms=new MemoryStream(buffer);
CryptoStream cs=new CryptoStream(ms,cryptoProvider.CreateDecryptor(KEY_192, IV_192),CryptoStreamMode.Read);
StreamReader sr=new StreamReader(cs);
strResult = sr.ReadToEnd();
return strResult;
}
No comments:
Post a Comment