Reputation: 558
I need some help in encrypting and decrypting a DataTable object.
Problem Scenario:
Required Features:
Please assist.
Upvotes: 1
Views: 3073
Reputation: 5146
I am not sure that this is the best way to do this, but, it seems that would just be to iterate through the rows and columns (i.e. just use a double for loop, or foreach) and use this: http://msdn.microsoft.com/en-us/library/system.security.cryptography.tripledes.aspx to do the Triple DES. This code is NOT checked, but it should look like this:
String fin = cell1.ToString();
//Create variables to help with read and write.
byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
long rdlen = 0; //This is the total number of bytes written.
long totlen = fin.Length; //This is the total length of the input file.
int len; //This is the number of bytes to be written at a time.
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(cell1, tdes.CreateEncryptor(tdesKey, tdesIV), CryptoStreamMode.Write);
Console.WriteLine("Encrypting...");
//Read from the input file, then encrypt and write to the output file.
while(rdlen < totlen)
{
len = fin.Read(bin, 0, 100);
encStream.Write(bin, 0, len);
rdlen = rdlen + len;
Console.WriteLine("{0} bytes processed", rdlen);
}
Upvotes: 0
Reputation: 27342
My thoughts would be to convert to XML (DataSet.GetXML) and then do encryption on this XML Data. Have a look at the System.Security.Cryptography Namespace (TripleDES Class). Decrypting and converting your XML back to a DataSet is then trivial.
Upvotes: 2