我在加密和解密DataTable对象时需要一些帮助。
问题场景:
必备功能:
请协助。
答案 0 :(得分:2)
我的想法是转换为XML(DataSet.GetXML),然后对此XML数据进行加密。查看System.Security.Cryptography命名空间(TripleDES Class)。然后将XML解密并转换回DataSet是微不足道的。
答案 1 :(得分:0)
我不确定这是执行此操作的最佳方法,但是,似乎只是遍历行和列(即只使用double for循环或foreach)并使用此:{{ 3}}做三重DES。 不检查此代码,但它应如下所示:
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);
}