[Mono-bugs] [Bug 79499][Wis] New - RijndaelCipher works differently on windows ms.net and linux mono

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Sep 25 20:01:19 EDT 2006


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 carlos at applianz.com.

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

--- shadow/79499	2006-09-25 20:01:19.000000000 -0400
+++ shadow/79499.tmp.8213	2006-09-25 20:01:19.000000000 -0400
@@ -0,0 +1,70 @@
+Bug#: 79499
+Product: Mono: Class Libraries
+Version: 1.1
+OS: other
+OS Details: Gentoo 32bit
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System.Security
+AssignedTo: sebastien at ximian.com                            
+ReportedBy: carlos at applianz.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: RijndaelCipher works differently on windows ms.net and linux mono
+
+I am trying to encrypt a value on mono 1.1.10.1 using RijndaelCipher but
+windows XP with ms.net can not decrypt it. I tried encrypting the same data
+with both ms.net and mono and the returned values were different. 
+
+Below are the methods used for encrypting and decrypting:
+
+public static string EncryptAES( string text, string salt )
+        {
+            SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
+            string saltHash = Encoding.ASCII.GetString(
+sha1.ComputeHash(Encoding.ASCII.GetBytes(salt)) );
+            RijndaelManaged RijndaelCipher = new RijndaelManaged();
+            byte[] plainbytes = System.Text.Encoding.Unicode.GetBytes( text );
+            byte[] bsalt = Encoding.ASCII.GetBytes(
+saltHash.Length.ToString() );
+            PasswordDeriveBytes key = new PasswordDeriveBytes( saltHash,
+bsalt );
+            ICryptoTransform encryptor = RijndaelCipher.CreateEncryptor(
+key.GetBytes(32), key.GetBytes(16) );
+            MemoryStream ms = new MemoryStream();
+            CryptoStream cs = new CryptoStream( ms, encryptor,
+CryptoStreamMode.Write );
+            cs.Write( plainbytes, 0, plainbytes.Length );
+            cs.FlushFinalBlock();
+            byte[] cryptbytes = ms.ToArray();
+            ms.Close();
+            cs.Close();
+            return Convert.ToBase64String(cryptbytes);
+        }
+
+        public static string DecryptAES( string text, string salt )
+        {
+            SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
+            string saltHash = Encoding.ASCII.GetString(
+sha1.ComputeHash(Encoding.ASCII.GetBytes(salt)) );
+            RijndaelManaged  RijndaelCipher = new RijndaelManaged();
+            byte[] cryptbytes = Convert.FromBase64String( text );
+            byte[] bsalt = Encoding.ASCII.GetBytes(
+saltHash.Length.ToString() );
+            PasswordDeriveBytes key = new PasswordDeriveBytes( saltHash,
+bsalt );
+            ICryptoTransform decryptor = RijndaelCipher.CreateDecryptor(
+key.GetBytes(32), key.GetBytes(16) );
+            MemoryStream  ms = new MemoryStream( cryptbytes );
+            CryptoStream  cs = new CryptoStream( ms, decryptor,
+CryptoStreamMode.Read );
+            byte[] plainbytes = new byte[cryptbytes.Length];
+            int bytecount = cs.Read( plainbytes, 0, plainbytes.Length );
+            ms.Close();
+            cs.Close();
+            return Encoding.Unicode.GetString( plainbytes, 0, bytecount );
+        }


More information about the mono-bugs mailing list