Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

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

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???
Posted
Updated 27-Sep-13 5:05am
v2

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
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900