تابعی هایی برای کد کردن و دی کد کردن اطلاعاتی مانند کلمه عبور , پارامترها و ...
جهت بالا بردن امنیت نقل و انتقال داده و همچنین بانک اطلاعات و ...
publicstring EncryptText(string strText)
{
return Encrypt(strText, "&%#@?,:*");
}
publicstring DecryptText(string strText)
{
return Decrypt(strText, "&%#@?,:*");
}
privatestring Encrypt(string strText, string strEncrKey)
{
byte[] byKey;
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8));
DESCryptoServiceProvider des = newDESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
MemoryStream ms = newMemoryStream();
CryptoStream cs = newCryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
returnConvert.ToBase64String(ms.ToArray());
}
catch (Exception ex)
{
return ex.Message;
}
}
privatestring Decrypt(string strText, string sDecrKey)
{
byte[] byKey;
byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
byte[] inputByteArray;
// inputByteArray.Length = strText.Length;
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0, 8));
DESCryptoServiceProvider des = newDESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(strText);
MemoryStream ms = newMemoryStream();
CryptoStream cs = newCryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (Exception ex)
{
return ex.Message;
}
}