public static T DeSerializeAES <T>(string filePath) { T obj; using (FileStream fs = new FileStream(filePath, FileMode.Open)) { BinaryReader br = new BinaryReader(fs); var so = br.ReadBytes((int)fs.Length); var s = AESEncryption.AESDecrypt(so); obj = DeSerialize <T>(s); } return(obj); }
//定义Color属性的序列化为cat节点的属性 [XmlAttribute("color")] //要求不序列化Speed属性 [XmlIgnore] //设置Saying属性序列化为Xml子元素 [XmlElement("saying")] public static void SerializeAES <T>(T obj, string filePath) { if (File.Exists(filePath)) { File.Delete(filePath); } using (FileStream fs = new FileStream(filePath, FileMode.Create)) { var s = Serialize <T>(obj); var so = AESEncryption.AESEncrypt(s); BinaryWriter bw = new BinaryWriter(fs); bw.Write(so); } }