2003-02-08 Sebastien Pouliot <spouliot@videotron.ca>
[mono.git] / mcs / class / corlib / System.Security.Cryptography / RSAPKCS1SignatureDeformatter.cs
1 //
2 // RSAPKCS1SignatureDeformatter.cs - Handles PKCS#1 v.1.5 signature decryption.
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
9
10 using System;
11 using Mono.Security.Cryptography;
12
13 namespace System.Security.Cryptography { 
14         
15         public class RSAPKCS1SignatureDeformatter : AsymmetricSignatureDeformatter {
16         
17                 private RSA rsa;
18                 private string hashName;
19         
20                 public RSAPKCS1SignatureDeformatter () 
21                 {
22                         rsa = null;
23                 }
24         
25                 public RSAPKCS1SignatureDeformatter (AsymmetricAlgorithm key) 
26                 {
27                         SetKey (key);
28                 }
29         
30                 public override void SetHashAlgorithm (string strName) 
31                 {
32                         if (strName == null)
33                                 throw new ArgumentNullException ("strName");
34                         hashName = strName;
35                 }
36         
37                 public override void SetKey (AsymmetricAlgorithm key) 
38                 {
39                         if (key != null)
40                                 rsa = (RSA)key;
41                         // here null is accepted with an ArgumentNullException!
42                 }
43         
44                 public override bool VerifySignature (byte[] rgbHash, byte[] rgbSignature) 
45                 {
46                         if ((rsa == null) || (hashName == null))
47                                 throw new CryptographicUnexpectedOperationException ();
48                         if ((rgbHash == null) || (rgbSignature == null))
49                                 throw new ArgumentNullException ();
50         
51                         string oid = CryptoConfig.MapNameToOID (hashName);
52                         return PKCS1.Verify_v15 (rsa, oid, rgbHash, rgbSignature);
53                 }
54         }
55 }