[Mono-bugs] [Bug 76483][Maj] New - Triple DES Encryption Throws Exception

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Oct 19 14:34:29 EDT 2005


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 yogendrathakur at gmail.com.

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

--- shadow/76483	2005-10-19 14:34:29.000000000 -0400
+++ shadow/76483.tmp.1741	2005-10-19 14:34:29.000000000 -0400
@@ -0,0 +1,154 @@
+Bug#: 76483
+Product: Mono: Class Libraries
+Version: 1.1
+OS: Red Hat 8.0
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: System.Security
+AssignedTo: sebastien at ximian.com                            
+ReportedBy: yogendrathakur at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Triple DES Encryption Throws Exception
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+
+Description of Problem:
+------------------------
+
+Following Code works fine in Microsoft .NET 1.1  but throws exception 
+while running using Mono 1.1.9.2
+
+[Code]
+======
+
+//This code encrypts string using Triple DES and decrypt it.
+string originalString = "Powered By Mono.Powered By Mono.";
+string encryptedString = null;
+string decryptedString = null;
+
+//Some randomly typed encryption key.
+byte[] encryptionKey = new byte[]{
+									
+	156,189,111,111,
+									
+	112,12,112,16,
+									
+	134,123,134,24,
+									
+	112,56,2,242,
+									
+	78,124,112,76,
+									
+	112,134,187,78		
+									};
+	
+
+byte[] initializationVector = new byte[]
+								{
+								
+	0,0,0,0,
+								
+	0,0,0,0,
+								
+	0,0,0,0,
+								
+	0,0,0,0,
+								
+	0,0,0,0,
+								
+	0,0,0,0,
+								
+	0,0,0,0,
+								
+	0,0,0,0
+								};
+
+
+//Encrypt Data	
+TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider
+();
+tDes.Mode = CipherMode.CBC;
+tDes.Padding = PaddingMode.None;
+
+MemoryStream memEncrypt = new MemoryStream();
+CryptoStream encryptStream = new CryptoStream
+(memEncrypt,tDes.CreateEncryptor(encryptionKey,initializationVector), 
+CryptoStreamMode.Write);
+	
+StreamWriter sw = new StreamWriter(encryptStream);
+sw.Write(originalString);
+sw.Flush();
+encryptStream.FlushFinalBlock();
+memEncrypt.Flush();
+
+encryptedString= Convert.ToBase64String(memEncrypt.GetBuffer(), 0, (int)
+memEncrypt.Length);
+sw.Close();
+encryptStream.Close();
+memEncrypt.Close();
+
+//Decrypt Data
+byte[] buffer =  Convert.FromBase64String(encryptedString);
+MemoryStream memDecrypt = new MemoryStream(buffer);
+CryptoStream stream = new CryptoStream(memDecrypt,tDes.CreateDecryptor
+(encryptionKey,initializationVector), CryptoStreamMode.Read);
+StreamReader sr = new StreamReader(stream);
+decryptedString = sr.ReadToEnd();
+sr.Close();
+stream.Close();
+memDecrypt.Close();
+
+//Display 
+Console.WriteLine("Original Data  : " + originalString);
+Console.WriteLine("Encrypted Data : " + encryptedString);
+Console.WriteLine("Decrypted Data : " + decryptedString);
+
+Steps to reproduce the problem:
+1. Add above code to Console Application
+2. Compile aplication.
+3. Run Aplication
+
+Actual Results:
+------------------
+
+1) On Microsoft .NET 1.1 Framework
+===================================
+Original Data  : Powered By Mono.Powered By Mono.
+Encrypted Data : Xh/Xeg9vEq2W7BOw8SWsgnJMqMa11+HtB84MVCg/
+Decrypted Data : Powered By Mono.Powered By Mono.
+
+2) On Mono 1.1.9.2
+===================
+
+Unhandled Exception: System.Security.Cryptography.CryptographicException: 
+IV length cannot be larger than block size
+in <0x000e0> System.Security.Cryptography.SymmetricAlgorithm:set_IV 
+(System.Byte[] value)
+in <0x00020> 
+System.Security.Cryptography.TripleDESCryptoServiceProvider:CreateEncrypto
+r (System.Byte[] rgbKey, System.Byte[] rgbIV)
+in <0x0013d> TestEncryption.TestEncryption:Main (System.String[] args)
+
+
+
+
+Expected Results:
+------------------
+On Mono
+========
+Original Data  : Powered By Mono.Powered By Mono.
+Encrypted Data : Xh/Xeg9vEq2W7BOw8SWsgnJMqMa11+HtB84MVCg/
+Decrypted Data : Powered By Mono.Powered By Mono.
+
+How often does this happen? 
+Always.
+
+Additional Information:
+None.


More information about the mono-bugs mailing list