[Mono-bugs] [Bug 78744][Nor] New - Bug in AsymmetricSignatureDeformatter.VerifySignature

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sat Jul 1 09:51:02 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 diegomesa at vpssoftware.com.

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

--- shadow/78744	2006-07-01 09:51:02.000000000 -0400
+++ shadow/78744.tmp.6109	2006-07-01 09:51:02.000000000 -0400
@@ -0,0 +1,81 @@
+Bug#: 78744
+Product: Mono: Class Libraries
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System.Security
+AssignedTo: sebastien at ximian.com                            
+ReportedBy: diegomesa at vpssoftware.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Bug in AsymmetricSignatureDeformatter.VerifySignature
+
+Description of Problem:
+
+In the class AsymmetricSignatureDeformatter, when I call the method:
+
+public virtual bool VerifySignature (HashAlgorithm hash, byte[] rgbSignature) 
+
+I get an CryptographicUnexpectedOperationException that say "Missing hash
+algorithm."
+
+I review the AsymmetricSignatureDeformatter source code, and I think that
+the bug is that the method SetHashAlgorithm method isn't called before that
+VerifySignature (hash.Hash, rgbSignature);
+
+The fixed method I think that will be:
+
+class AsymmetricSignatureDeformatter {
+
+ /*..../*
+
+ public virtual bool VerifySignature (HashAlgorithm hash, byte[] 
+rgbSignature) 
+ {
+   if (hash == null)
+     throw new ArgumentNullException ("hash");
+
+   //This fix the bug
+   SetHashAlgorithm (hash.ToString ());
+  
+   return VerifySignature (hash.Hash, rgbSignature);
+ }
+}
+
+
+This code shows the problem: 
+
+string text = "text to sign";
+			
+AsymmetricAlgorithm asymmetricAlg = AsymmetricAlgorithm.Create("RSA");
+			
+AsymmetricSignatureFormatter signatureFormmater = new
+RSAPKCS1SignatureFormatter(asymmetricAlg);
+			
+HashAlgorithm hashAlg = HashAlgorithm.Create("SHA1");
+			hashAlg.ComputeHash(System.Text.Encoding.UTF8.GetBytes(text));
+
+byte [] signature = signatureFormmater.CreateSignature(hashAlg);
+			
+Console.WriteLine(Convert.ToBase64String(signature));
+			
+AsymmetricSignatureDeformatter signatureDeformmater = new
+RSAPKCS1SignatureDeformatter(asymmetricAlg);
+			
+if (signatureDeformmater.VerifySignature(hashAlg, signature)) 
+  Console.WriteLine("Signature OK");		
+else
+  Console.WriteLine("Bad Signature");
+
+
+Actual Results:
+CryptographicUnexpectedOperationException "Missing hash algorithm."
+
+Expected Results:
+"Signature OK"


More information about the mono-bugs mailing list