2004-04-05 Bernie Solomon <bernard@ugsolutions.com>
[mono.git] / mcs / class / corlib / System.Security.Cryptography / RSAPKCS1KeyExchangeDeformatter.cs
1 //
2 // RSAPKCS1KeyExchangeDeformatter.cs - Handles PKCS#1 v.1.5 keyex decryption.
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2002 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 RSAPKCS1KeyExchangeDeformatter : AsymmetricKeyExchangeDeformatter {
16         
17                 private RSA rsa;
18                 private string param;
19                 private RandomNumberGenerator random;
20         
21                 public RSAPKCS1KeyExchangeDeformatter () 
22                 {
23                         rsa = null;
24                 }
25         
26                 public RSAPKCS1KeyExchangeDeformatter (AsymmetricAlgorithm key) 
27                 {
28                         SetKey (key);
29                 }
30         
31                 public override string Parameters {
32                         get { return param; }
33                         set { param = value; }
34                 }
35         
36                 public RandomNumberGenerator RNG {
37                         get { return random; }
38                         set { random = value; }
39                 }
40         
41                 public override byte[] DecryptKeyExchange (byte[] rgbData) 
42                 {
43                         if (rsa == null)
44                                 throw new CryptographicException ();
45                         return PKCS1.Decrypt_v15 (rsa, rgbData);
46                 }
47         
48                 public override void SetKey (AsymmetricAlgorithm key) 
49                 {
50                         if (key is RSA) {
51                                 rsa = (RSA)key;
52                         }
53                         else
54                                 throw new CryptographicException ();
55                 }
56         }
57 }