[Mono-bugs] [Bug 40689][Maj] New - DESCryptoServiceProvider() throws a Exception and do no depadding

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Wed, 2 Apr 2003 16:14:33 -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 henning@skalatan.de.

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

--- shadow/40689	Wed Apr  2 16:14:33 2003
+++ shadow/40689.tmp.18068	Wed Apr  2 16:14:33 2003
@@ -0,0 +1,92 @@
+Bug#: 40689
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: Gentoo Linux 1.4, Kernel 2.4.20
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: henning@skalatan.de               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: DESCryptoServiceProvider() throws a Exception and do no depadding
+
+Description of Problem:  
+ 
+I just wrote a little c# application to decrypt data provided by a .NET 
+application. This data is DES encrypted. I´m using the 
+DESCryptoServiceProvider() from System.Security.Cryptography. 
+My first problem is, that mono throws everytime a exception.  
+ 
+> Exception: System.IndexOutOfRangeException: Array index is out of range 
+> in <0x0011b> 00  
+> System.Security.Cryptography.SymmetricTransform:FinalDecrypt 
+> (byte[],int,int) in <0x00088> 00   
+> System.Security.Cryptography.SymmetricTransform:TransformFinalBlock 
+> (byte[],int,int) 
+> in <0x00134> 00 System.Security.Cryptography.CryptoStream:Close () 
+> in <0x00341> 00 helpIMBA.DecryptData:.ctor (string,string,string) 
+> in <0x0003b> 00 helpIMBA.EntschluesselIMBA:.ctor (string,string,string) 
+> in <0x0012a> 00 .helpIMBA:Main (string[] 
+ 
+i testet the DESCryptoServiceProvider() a little bit more. The problem is not  
+that the CryptoStream close the internal stream, Gonzalo Paniagua Javier  
+fixed that for a few days.  
+ 
+The problem is the padding. 
+ 
+The SymmetricAlgorithm fills always the last block of the filestream up to the  
+blocksize of the Crypto Provider. At the end of the decoding, the method   
+FlushFinalBlock() from CryptoStream is called.  
+ 
+These method calls TransformFinalBlock(...) of SymmetricAlgorithm.  
+ 
+TransformFinalBlock calls FinalDecrypt(...). These method switch into  
+Paddingmode PKCS7, which starts a array operation on the passed parameters. 
+ 
+The passed parameters are always 0, as the last block was equal the blocksize,  
+and the data was completly decrypted.  
+No block left over --> ArrayIndex Eception. 
+ 
+The same error leading to the padding issue: 
+ 
+> The second problem is, that DES CryptoStream add six bytes of "06" to the 
+> end of every file.  
+ 
+As the last block with the padding is decrypted, before FinalDecrypt(...) is  
+called, no depadding takes place. 
+ 
+I attached sample code to reproduce the first problem. Comment out the  
+CrytoStream.Close() prevent the first Exception, but not the padding problem. 
+ 
+[Except from my emails with Sébastien Pouliot] 
+ 
+ 
+Steps to reproduce the problem: 
+ 
+- Run the attached code sample  
+  
+ 
+Actual Results: 
+ 
+CVS from 30.03.2003, Exception and faulty padding 
+ 
+ 
+Expected Results: 
+ 
+No exception an the right padding/ depadding :-) 
+ 
+ 
+How often does this happen?  
+ 
+everytime 
+ 
+ 
+Additional Information: 
+ 
+Testet my code and the example with the MS Runtime, no problems.