将加密的数据表保存到文件 [英] Saving a DataTable encrypted to a file

查看:179
本文介绍了将加密的数据表保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的C#代码有问题,到目前为止,互联网仍然无济于事……我已经尝试了30种解决方案,但它们只是没有功能,或者只适合于字符串等等.

我只想将DataTable保存在一个文件中,以便没有人可以读取它.序列化太不安全,顺便说一句也不起作用.这是决定性的代码:

Hello everybody,

I have a problem with my C# code and as alwlays the internet was no help so far... I''ve tried about 30 solution, but they just had no funciont or were only good for strings and so on.

I just want to save my DataTable in a file so that nobody can read it. Serialization is too unsafe and it doesn''t work either btw. This is the deciding code:

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);


密码:32byte
IV:16byte

实际上,这段代码产生了几行二进制代码,但其余全部完全是
有谁知道为什么这行不通并且可能有可行的解决方案?


password: 32byte
IV: 16byte

Actually this code produces a couple of binary lines, but the whole rest is completely
Does anybody know why that does not work and maybe have a working solution???

推荐答案

首先将DataTable转换为XML.然后,对内存中的XML字符串进行加密(保存之前)或对XML文件进行加密.那就是我会做的.

希望对您有帮助
Convert the DataTable to XML first. Then encrypt the XML string in Memory (before saving) or encrypt the XML File. That is what I would do.

Hope this helps


您可以查看以下内容:
加密数据表对象 [加密和加密解密数据表对象 [ ^ ]
You could have a look at these:
Encrypting Data table object [^]
Encryption & Decryption of DataTable Object[^]


这篇关于将加密的数据表保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆