PDA

View Full Version : مشکل در Decrypt کردن ابجکت سریالیز شده



s.khoshfekran
شنبه 01 خرداد 1389, 18:26 عصر
سلام دوستان
من دو تابع گذاشتم که یکی واسه Encrypt کردن ابجکت سریالیز شده هست که مشکلی نداره ولی تابع Decrypt کردن ان error میده ممنون میشم کمک کنید.
اگر هم کسی کد مشابه این رو داره ممنون میشم بزاره اینجا!!



publicvoid Serialize(string Path, object obj, string Password)
{
RijndaelManaged rm = newRijndaelManaged();
FileStream fs = newFileStream(Path, FileMode.CreateNew, FileAccess.ReadWrite);
PasswordDeriveBytes pdb = newPasswordDeriveBytes(Password, Encoding.ASCII.GetBytes(Password.Length.ToString() ));
rm.Key = pdb.GetBytes(32);
rm.IV = pdb.GetBytes(16);
CryptoStream cs = newCryptoStream(fs, rm.CreateEncryptor(), CryptoStreamMode.Write);
BinaryFormatter bf = newBinaryFormatter();
bf.Serialize(cs,obj);
cs.FlushFinalBlock();
fs.Close();
}




publicobject DeSerialize(string path, string Password)
{
RijndaelManaged rm = newRijndaelManaged();
FileStream fs = newFileStream(path, FileMode.Open, FileAccess.Read);
PasswordDeriveBytes pdb = newPasswordDeriveBytes(Password, Encoding.ASCII.GetBytes(Password.Length.ToString() ));
rm.Key = pdb.GetBytes(32);
rm.IV = pdb.GetBytes(16);
CryptoStream cs = newCryptoStream(fs, rm.CreateDecryptor(), CryptoStreamMode.Read);
BinaryFormatter bf = newBinaryFormatter();
return bf.Deserialize(cs);
}

s.khoshfekran
یک شنبه 02 خرداد 1389, 19:20 عصر
اساتید محترم یعنی کسی در مورد رمزگذاری بر روی داده های سریالیز شده ی Binary نطری نداره ؟؟