MSMVPS.COM
The Ultimate Destination for Blogs by Current and Former Microsoft Most Valuable Professionals.

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
Filed under:

Comments

Montaque wrote re: Remember to invoke FlushFinalBlock()
on 09-03-2004 14:49
Montaque wrote re: Remember to invoke FlushFinalBlock()
on 09-24-2004 2:29
TrackBack wrote re:Remember to invoke FlushFinalBlock()
on 04-16-2005 2:37
^_~
Montaque wrote re: Remember to invoke FlushFinalBlock()
on 10-06-2005 0:52
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

Add a Comment

(required)  
(optional)
(required)  
Remember Me?


Copyright © is the original authors. Blog site is an independent site not sponsored by Microsoft. The Yoda blog server and the Brianna SQL server would like to thank www.ownwebnow.com and www.exchangedefender.com. They wouldn't be here and broadcasting without the generosity of Vlad Mazek and his companies.

Powered by Community Server (Commercial Edition), by Telligent Systems