2 // RSAPKCS1KeyExchangeFormatter.cs: Handles PKCS#1 v.1.5 keyex encryption.
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
11 using Mono.Security.Cryptography;
13 namespace System.Security.Cryptography {
15 // LAMESPEC: There seems no way to select a hash algorithm. The default
16 // algorithm, is SHA1 because the class use the PKCS1MaskGenerationMethod -
17 // which default to SHA1.
18 public class RSAPKCS1KeyExchangeFormatter: AsymmetricKeyExchangeFormatter
21 private RandomNumberGenerator random;
23 public RSAPKCS1KeyExchangeFormatter ()
27 public RSAPKCS1KeyExchangeFormatter (AsymmetricAlgorithm key)
32 public RandomNumberGenerator Rng
34 get { return random; }
35 set { random = value; }
38 public override string Parameters
40 get { return "<enc:KeyEncryptionMethod enc:Algorithm=\"http://www.microsoft.com/xml/security/algorithm/PKCS1-v1.5-KeyEx\" xmlns:enc=\"http://www.microsoft.com/xml/security/encryption/v1.0\" />"; }
43 public override byte[] CreateKeyExchange (byte[] rgbData)
46 throw new CryptographicException ();
48 random = RandomNumberGenerator.Create (); // create default
49 return PKCS1.Encrypt_v15 (rsa, random, rgbData);
52 public override byte[] CreateKeyExchange (byte[] rgbData, Type symAlgType)
54 // documentation says that symAlgType is not used !?!
55 // FIXME: must be the same as previous method ?
56 return CreateKeyExchange (rgbData);
59 public override void SetKey (AsymmetricAlgorithm key)
66 throw new InvalidCastException ();
68 // here null is accepted!