1. //解密,返回解密后的 DateSet,传入的参数是需解密的文件名  
  2.         public DataSet EnCrypt(string InName)  
  3.         {  
  4.             FileStream fsIn = new FileStream(InName,FileMode.Open,FileAccess.Read);  
  5.               
  6.             byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};  
  7.             byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};  
  8.  
  9.             RijndaelManaged RMCrypto = new RijndaelManaged();  
  10.  
  11.             System.Security.Cryptography.CryptoStream cs = new CryptoStream(fsIn,RMCrypto.CreateDecryptor(Key,IV),CryptoStreamMode.Read);  
  12.             DataSet myDataSet = new DataSet ();  
  13.             System.Xml.XmlTextReader XmlReader ;      
  14.             try 
  15.             {     
  16.                 XmlReader = new System.Xml.XmlTextReader (cs);                    
  17.                 myDataSet.ReadXml(XmlReader);                     
  18.                 XmlReader.Close ();  
  19.                 fsIn.Close();  
  20.             }  
  21.             catch(System.Exception e)    
  22.             {  
  23.             }             
  24.             return myDataSet;  
  25.         }  
  26.  
  27.         //加密,InName表示要加密的文件,OutName为加密后的文件名  
  28.         public void Crypt(string InName,string OutName)  
  29.         {  
  30.             FileStream fsIn = new FileStream(InName,FileMode.Open,FileAccess.Read);  
  31.  
  32.             FileStream fsOut = new FileStream(OutName,FileMode.Create,FileAccess.Write);  
  33.  
  34.             byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};  
  35.             byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};  
  36.  
  37.             RijndaelManaged RMCrypto = new RijndaelManaged();  
  38.  
  39.             System.Security.Cryptography.CryptoStream cs = new CryptoStream(fsOut,RMCrypto.CreateEncryptor(Key,IV),CryptoStreamMode.Write);  
  40.  
  41.             byte[] bin = new byte[100]; //This is intermediate storage for the encryption.  
  42.             long rdlen = 0;              //This is the total number of bytes written.  
  43.             long totlen = fsIn.Length;    //This is the total length of the input file.  
  44.             int len;                     //This is the number of bytes to be written at a time.  
  45.               
  46.             while(rdlen < totlen)  
  47.             {  
  48.                 len = fsIn.Read(bin, 0, 100);  
  49.                 cs.Write(bin, 0, len);  
  50.                 rdlen = rdlen + len;  
  51.                 Console.WriteLine("{0} bytes processed", rdlen);  
  52.             }  
  53.    
  54.             cs.Close();    
  55.             fsOut.Close();  
  56.             fsIn.Close();                     
  57.  
  58.         }