[Mono-bugs] [Bug 40394][Wis] New - Problem encrypting data using CryptoStream with MemoryStream

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Thu, 27 Mar 2003 12:36:00 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by joergr@voelcker.com.

http://bugzilla.ximian.com/show_bug.cgi?id=40394

--- shadow/40394	Thu Mar 27 12:36:00 2003
+++ shadow/40394.tmp.25607	Thu Mar 27 12:36:00 2003
@@ -0,0 +1,90 @@
+Bug#: 40394
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Debian Woody
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: JoergR@voelcker.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Problem encrypting data using CryptoStream with MemoryStream
+
+Description of Problem:
+I have used CryptoStream to encrypt data and write it to a MemoryStream
+object. When the CryptoStream object is disposed an exception is raised.
+
+Using MS.NET the same source runs fine.
+
+
+Steps to reproduce the problem:
+Following sample reproduces this behaviour:
+
+using System;
+using System.IO;
+using System.Security.Cryptography;
+using System.Text;
+
+
+namespace MonoTest
+{
+    
+    public class MainClass
+    {
+        public static void Main()
+        {
+            try
+            {
+                SymmetricAlgorithm algo = new RijndaelManaged();
+                                
+       			MemoryStream mem;
+                CryptoStream crypt;
+                byte []	toEncrypt = Encoding.Unicode.GetBytes("Please
+encode me!");
+                byte [] result = null;
+			
+                using ( mem = new MemoryStream() )
+                {
+                    using ( crypt = new CryptoStream(mem,
+algo.CreateEncryptor(), CryptoStreamMode.Write) )
+                    {
+                        crypt.Write(toEncrypt, 0, toEncrypt.Length);
+                        crypt.FlushFinalBlock();
+                    }
+                    
+                    result = mem.ToArray();
+                }
+
+                Console.WriteLine("Crypted. Size = {0}", result.Length);
+            }
+            catch( Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+                Console.WriteLine(ex.StackTrace);
+            }    
+        }
+    }
+}
+
+
+Actual Results:
+The object was used after being disposed
+in <0x00073> 00 System.IO.MemoryStream:CheckIfClosedThrowDisposed ()
+in <0x00015> 00 System.IO.MemoryStream:Write (byte[],int,int)
+in <0x001c7> 00 System.Security.Cryptography.CryptoStream:Close ()
+in <0x00014> 00 System.IO.Stream:System.IDisposable.Dispose ()
+in <0x0019b> 00 MonoTest.MainClass:Main ()
+
+Expected Results:
+Crypted. Size = 48
+
+How often does this happen? 
+Always.
+
+Additional Information: