2011-04-27 84 views
1

我需要一些幫助來加密和解密DataTable對象。DataTable對象的加密和解密

問題場景:

  • 加密 System.Data.DataTable對象的所有內容。

必需的功能:

  • 要使用Triple DES加密邏輯
  • 應該全部內容或所有細胞將所有列和/或行

請協助。

回答

0

我不確定這是做到這一點的最佳方式,但它似乎只是遍歷行和列(即只使用double for循環或foreach)並使用以下代碼:http://msdn.microsoft.com/en-us/library/system.security.cryptography.tripledes.aspx做三重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); 
}