2011-04-27 22 views
1

DataTableオブジェクトの暗号化と復号化に助けが必要です。DataTableオブジェクトの暗号化と復号化

問題のシナリオ: たSystem.Data.DataTableオブジェクトのすべてのコンテンツを暗号化

  • 。トリプル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); 
}