[英]How to create a encrypt writer and decrypt reader in C#
I am currently using XML Serialization to serialize a class instance. 我目前正在使用XML序列化来序列化一个类实例。
I like to create an encrypt StreamWriter to replace steamwriter. 我喜欢创建一个加密的StreamWriter来代替Steamwriter。 Is this a good way to do it?
这是一个好方法吗? If not what should I do?
如果没有,我该怎么办?
public class PO po = new PO ();
XmlSerializer serializer = new XmlSerializer(typeof(T));
TextWriter writer = new StreamWriter(filename);
serializer.Serialize(writer, po);
StreamWriter
is basically a wrapper around stream that provides additional APIs to convert from typed values (eg strings) to binary. StreamWriter
基本上是流的包装,它提供了其他API,以将类型化的值(例如字符串)转换为二进制。 As encryption often does not require knowledge of input encoding or any information other then just binary data, I would say an encrypted Stream
(wrapping normal Stream
) is a better choice. 由于加密通常只需要二进制数据就不需要输入编码或其他任何信息,我想说加密的
Stream
(包装普通Stream
)是更好的选择。
You can use CryptoStream
class which defines a stream that links data streams to cryptographic transformations. 您可以使用
CryptoStream
类,该类定义将数据流链接到密码转换的流。 You can find an example in the following link: http://www.obviex.com/Samples/Encryption.aspx 您可以在以下链接中找到示例: http : //www.obviex.com/Samples/Encryption.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.