Montaque

Nothing is impossible for MS .NET

Remember to invoke FlushFinalBlock()

When encrypting a stream with System.Security.DesCryptoServiceProvider, code sniipt like the following.

Byte []EncryedText=Convert.FromBase64String(this.textBox3.Text) ;

   System.IO.MemoryStream EncryptedStream=new System.IO.MemoryStream(EncryedText);

   System.IO.MemoryStream OutMS=new System.IO.MemoryStream();

   EncryptedStream.Seek(0,System.IO.SeekOrigin.Begin);

   System.Security.Cryptography.DESCryptoServiceProvider x_des=new DESCryptoServiceProvider();

   //??

   x_des.IV=m_IV;
   x_des.Key=m_Key;
   
   
   //???
   System.Security.Cryptography.CryptoStream encryptStream =new CryptoStream(OutMS,x_des.CreateDecryptor(),System.Security.Cryptography.CryptoStreamMode.Write);

   

   encryptStream.Write(EncryedText,0,EncryedText.Length);
   encryptStream.FlushFinalBlock();

   Byte[] outText=new byte[(Int32)OutMS.Length];
   OutMS.Seek(0,System.IO.SeekOrigin.Begin);
   //???????
   OutMS.Read(outText,0,(Int32)OutMS.Length);
   MessageBox.Show(System.Text.Encoding.Unicode.GetString(outText));

 

if the FlushFinalBlock is missed, you probably will not get the full encrypted text

Posted: Apr 09 2004, 06:49 AM by Montaque | with 4 comment(s)
Filed under:

Comments

Montaque said:

# September 3, 2004 2:49 PM

Montaque said:

# September 24, 2004 2:29 AM

TrackBack said:

^_~
# April 16, 2005 2:37 AM

Montaque said:

Thank you I am learning of new things all day! And it is good to know of my RSS already work. I think I need add button of RSS to make this thing clear.
But more work to do!
http://www.52z.com
http://www.k198.com
http://www.yxdown.com
http://www.itcnw.com
# October 6, 2005 12:52 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)