1
我有一個WPF應用程序包含這個類:*反序列化的C#
{[Serializable]
public class Parametres
{
private string admin_login;
private string admin_pwd;
private string server;
private string db;
private string user;
private string pwd;}
我序列具有這種功能的對象:
public static void Serialize_Parametres(string filename, Parametres obj)
{
using (FileStream fs = File.Open(filename, FileMode.OpenOrCreate))
{
using (CryptoStream cs = new CryptoStream(fs, key.CreateEncryptor(), CryptoStreamMode.Write))
{
XmlSerializer xmlser = new XmlSerializer(typeof(Parametres));
xmlser.Serialize(cs, obj);
}
}
}
它的正常工作,並生成一個文件txt文件,但是當我試圖反序列化這個文件,並得到這個函數的對象參數:
public static Parametres DeSerialize_Parametres(string filename)
{
using (FileStream fs = File.Open(filename, FileMode.Open))
{
using (CryptoStream cs = new CryptoStream(fs, key.CreateDecryptor(), CryptoStreamMode.Read))
{
XmlSerializer xmlser = new XmlSerializer(typeof(Parametres));
return (Parametres)xmlser.Deserialize(cs);
}
}
}
我得到了這個錯誤Length of the data to decrypt is invalid
在線return (Parametres)xmlser.Deserialize(cs);
究竟是這個錯誤的原因是什麼?我該如何解決它?
http://stackoverflow.com/questions/942139/length-of-the-data-to-decrypt-is-invalid –