
byte[] messsage = EnCoding.UTF8.GetBytes(request); // Send message to the server. sslStream.Write(messsage); sslStream.Flush(); // read the response byte[] buffer = new byte[2048]; StringBuilder messageData = new StringBuilder(); int bytes = -1; do { bytes = sslStream.Read(buffer,buffer.Length); // Use Decoder class to convert from bytes to UTF8 // in case a character spans two buffers. Decoder decoder = EnCoding.UTF8.GetDecoder(); char[] chars = new char[decoder.GetCharCount(buffer,bytes)]; decoder.GetChars(buffer,bytes,chars,0); messageData.Append(chars); // Check for ending tag. if (messageData.ToString().IndexOf(expectedEndTag) != -1) { break; } } while (bytes > 0); string response = messageData.ToString(); using (XmlReader reader = XmlReader.Create(new StringReader(response))) { reader.ReadToFollowing("Success"); string successVal = reader.ReadElementContentAsstring(); success = bool.Parse(successVal); }解决方法 基于答案,并且鉴于字符串是不可变的,您应该编写自己的使用char []的XML解析器.完成解析后,擦除char数组内容.要在程序中使用敏感数据,请使用 SecureString作为@Ga berber和评论中建议的@Mumbo. 它很难并且重复工作,但是这样你就可以确保在解析后立即擦除内存.
总结以上是内存溢出为你收集整理的在C#中安全地解析XML全部内容,希望文章能够帮你解决在C#中安全地解析XML所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)