我想将DataTable
保存在文件中,以便任何人都无法阅读:
private DataTable machineTable = new DataTable();
private Rijndael crypto = Rijndael.Create();
private FileStream stream;
...
this.crypto.IV = ASCIIEncoding.ASCII.GetBytes(IV);
this.crypto.Key = ASCIIEncoding.ASCII.GetBytes(password);
this.stream = new FileStream(Global.MachineParametersDataFile, FileMode.OpenOrCreate, FileAccess.Write);
CryptoStream cryptoStream = new CryptoStream(this.stream, crypto.CreateEncryptor(this.crypto.Key, this.crypto.IV), CryptoStreamMode.Write);
this.machineTable.WriteXml(stream, XmlWriteMode.WriteSchema, true);
密码:32 字节IV:16byte
我的代码生成了几条二进制行,但其余部分完全没有加密。
答案 0 :(得分:3)
您正在写入流而不是cryptoStream。
this.machineTable.WriteXml(cryptoStream, XmlWriteMode.WriteSchema, true);