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