s.khoshfekran
شنبه 01 خرداد 1389, 19: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);
}
من دو تابع گذاشتم که یکی واسه 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);
}