Himalaya
چهارشنبه 18 آذر 1388, 11:03 صبح
publicstring Encode(string MyString)
{
string result;
try
{
byte[] IV = newbyte[8] { 240, 32, 45, 29, 0, 76, 173, 59 };
string cryptoKey = "Agg ois sdda bb Lopb oao nffex";
byte[] buffer = Encoding.ASCII.GetBytes(MyString);
TripleDESCryptoServiceProvider des = newTripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 = newMD5CryptoServiceProvider();
des.Key = MD5.ComputeHash(Encoding.ASCII.GetBytes(cryptoKey) );
des.IV = IV;
byte[] CodedBuffer = des.CreateEncryptor().TransformFinalBlock(buffer, 0, buffer.Length);
result = Convert.ToBase64String(CodedBuffer, 0, CodedBuffer.Length);
}
catch
{
result = null;
}
return result;
}
////////////////////////////////////////////////////////////////////////////
publicstring Decode(string CodedString64)
{
string result;
try
{
byte[] IV = newbyte[8] { 240, 32, 45, 29, 0, 76, 173, 59 };
string cryptoKey = "Agg ois sdda bb Lopb oao nffex";
byte[] buffer = Convert.FromBase64String(CodedString64);
TripleDESCryptoServiceProvider des = newTripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 = newMD5CryptoServiceProvider();
des.Key = MD5.ComputeHash(Encoding.ASCII.GetBytes(cryptoKey) );
des.IV = IV;
byte[] CodedBuffer = des.CreateDecryptor().TransformFinalBlock(buffer, 0, buffer.Length);
result = Encoding.ASCII.GetString(CodedBuffer);
}
catch
{
result = "";
}
return result;
}
یادم رفت اول سلام:لبخند:
اما مشکلم... میخوام بدونم کاراکتر + توی کوئری استرینگ کار خاصی انجام میده یا نه...
آخه من با 2 تابعی که تو اینجا گفتم کوئری استرینگ رو کد میکنم و پاس میدم به صفحه بعدی
... حالا اگه مثلا کاراکتر 1 رو کد کنم میشه مثلا این HWDldgUdKYg= که وقتی تو یه لیبیل این مقدار رو میگیرم و نمایش میدم همینو نشون میده ولی وقتی که مثلا 2 رو کد میکنم کوئری استرینگم میشه این VwuGJ1+W09k= که وقتی اونو میخونم و تو یه لیبل نمایش میدم میشه این VwuGJ1 W09k= ...یعنی به جای + اسپیس قرار میده که این باعث میشه دیگه نتونم به مقدار اولیه دسترسی پیدا کنم... این 2 تا تابع رو هم از همین سایت گرفتم
وقتی مقادیر رو توی سشن میریزم ،همه چیز درسته، اما نمیخوام با سشن کار کنم... تو کوکی هم همین مشکل وجود داره
حالا 2 تا سوال
1. میتونم مثلا بگم که اگه توی کوئری استرینگ اسپیس بود اونو با تابع ریپلیس تبدیل کن به + ولی خوب ممکنه که اون کاراکتر واقعا اسپیس باشه که در این صورت تبدیل کردنش اشتباه هستش... تا نظر دوستان چی باشه (البته این بیشتر نظر سنجی بود تا سوال :لبخند:)
2. آیا این مورد فقط واسه کاراکتر + پیش میاد یا ممکنه کاراکترهای دیگه ای هم این حالتو پیش بیارن
یه راه حل میخوام واسه این مشکل، لطفا
ممنون
{
string result;
try
{
byte[] IV = newbyte[8] { 240, 32, 45, 29, 0, 76, 173, 59 };
string cryptoKey = "Agg ois sdda bb Lopb oao nffex";
byte[] buffer = Encoding.ASCII.GetBytes(MyString);
TripleDESCryptoServiceProvider des = newTripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 = newMD5CryptoServiceProvider();
des.Key = MD5.ComputeHash(Encoding.ASCII.GetBytes(cryptoKey) );
des.IV = IV;
byte[] CodedBuffer = des.CreateEncryptor().TransformFinalBlock(buffer, 0, buffer.Length);
result = Convert.ToBase64String(CodedBuffer, 0, CodedBuffer.Length);
}
catch
{
result = null;
}
return result;
}
////////////////////////////////////////////////////////////////////////////
publicstring Decode(string CodedString64)
{
string result;
try
{
byte[] IV = newbyte[8] { 240, 32, 45, 29, 0, 76, 173, 59 };
string cryptoKey = "Agg ois sdda bb Lopb oao nffex";
byte[] buffer = Convert.FromBase64String(CodedString64);
TripleDESCryptoServiceProvider des = newTripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 = newMD5CryptoServiceProvider();
des.Key = MD5.ComputeHash(Encoding.ASCII.GetBytes(cryptoKey) );
des.IV = IV;
byte[] CodedBuffer = des.CreateDecryptor().TransformFinalBlock(buffer, 0, buffer.Length);
result = Encoding.ASCII.GetString(CodedBuffer);
}
catch
{
result = "";
}
return result;
}
یادم رفت اول سلام:لبخند:
اما مشکلم... میخوام بدونم کاراکتر + توی کوئری استرینگ کار خاصی انجام میده یا نه...
آخه من با 2 تابعی که تو اینجا گفتم کوئری استرینگ رو کد میکنم و پاس میدم به صفحه بعدی
... حالا اگه مثلا کاراکتر 1 رو کد کنم میشه مثلا این HWDldgUdKYg= که وقتی تو یه لیبیل این مقدار رو میگیرم و نمایش میدم همینو نشون میده ولی وقتی که مثلا 2 رو کد میکنم کوئری استرینگم میشه این VwuGJ1+W09k= که وقتی اونو میخونم و تو یه لیبل نمایش میدم میشه این VwuGJ1 W09k= ...یعنی به جای + اسپیس قرار میده که این باعث میشه دیگه نتونم به مقدار اولیه دسترسی پیدا کنم... این 2 تا تابع رو هم از همین سایت گرفتم
وقتی مقادیر رو توی سشن میریزم ،همه چیز درسته، اما نمیخوام با سشن کار کنم... تو کوکی هم همین مشکل وجود داره
حالا 2 تا سوال
1. میتونم مثلا بگم که اگه توی کوئری استرینگ اسپیس بود اونو با تابع ریپلیس تبدیل کن به + ولی خوب ممکنه که اون کاراکتر واقعا اسپیس باشه که در این صورت تبدیل کردنش اشتباه هستش... تا نظر دوستان چی باشه (البته این بیشتر نظر سنجی بود تا سوال :لبخند:)
2. آیا این مورد فقط واسه کاراکتر + پیش میاد یا ممکنه کاراکترهای دیگه ای هم این حالتو پیش بیارن
یه راه حل میخوام واسه این مشکل، لطفا
ممنون