2004-05-13 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.Security / System.Security.Cryptography.Xml / RSAKeyValue.cs
1 //
2 // RSAKeyValue.cs - RSAKeyValue implementation for XML Signature
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.Text;
11 using System.Xml;
12
13 namespace System.Security.Cryptography.Xml {
14
15         public class RSAKeyValue : KeyInfoClause {
16
17                 private RSA rsa;
18
19                 public RSAKeyValue () 
20                 {
21                         rsa = (RSA)RSA.Create ();
22                 }
23
24                 public RSAKeyValue (RSA key) 
25                 {
26                         rsa = key;
27                 }
28
29                 public RSA Key {
30                         get { return rsa; }
31                         set { rsa = value; }
32                 }
33
34                 public override XmlElement GetXml () 
35                 {
36                         XmlDocument document = new XmlDocument ();
37                         XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyValue, XmlSignature.NamespaceURI);
38                         xel.SetAttribute ("xmlns", XmlSignature.NamespaceURI);
39                         xel.InnerXml = rsa.ToXmlString (false);
40                         return xel;
41                 }
42
43                 public override void LoadXml (XmlElement value) 
44                 {
45                         if (value == null)
46                                 throw new ArgumentNullException ();
47
48                         if ((value.LocalName != XmlSignature.ElementNames.KeyValue) || (value.NamespaceURI != XmlSignature.NamespaceURI))
49                                 throw new CryptographicException ("value");
50
51                         rsa.FromXmlString (value.InnerXml);
52                 }
53         }
54 }