d9ae1ccbeadc95615663a0115cbb313f3dd589ee
[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
12 namespace System.Security.Cryptography { 
13
14 public class RSAPKCS1KeyExchangeDeformatter : AsymmetricKeyExchangeDeformatter {
15
16         private RSA rsa;
17         private string param;
18         private RandomNumberGenerator random;
19
20         public RSAPKCS1KeyExchangeDeformatter () 
21         {
22                 rsa = null;
23         }
24
25         public RSAPKCS1KeyExchangeDeformatter (AsymmetricAlgorithm key) 
26         {
27                 SetKey (key);
28         }
29
30         public override string Parameters {
31                 get { return param; }
32                 set { param = value; }
33         }
34
35         public RandomNumberGenerator RNG {
36                 get { return random; }
37                 set { random = value; }
38         }
39
40         public override byte[] DecryptKeyExchange (byte[] rgbData) 
41         {
42                 if (rsa == null)
43                         throw new CryptographicException ();
44                 return PKCS1.Decrypt_v15 (rsa, rgbData);
45         }
46
47         public override void SetKey (AsymmetricAlgorithm key) 
48         {
49                 if (key is RSA) {
50                         rsa = (RSA)key;
51                 }
52                 else
53                         throw new CryptographicException ();
54         }
55 }
56
57 }