1

我想将我的保存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:16 字节

我的代码生成了几行二进制代码,但其余部分完全未加密。

4

1 回答 1

3

您正在写入流而不是 cryptoStream。 this.machineTable.WriteXml(cryptoStream, XmlWriteMode.WriteSchema, true);

于 2013-09-27T14:07:35.473 回答