SignedXml.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. //
  2. // SignedXml.cs - SignedXml implementation for XML Signature
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. // Atsushi Enomoto <[email protected]>
  7. //
  8. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  9. // (C) 2004 Novell (http://www.novell.com)
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System.Collections;
  32. using System.IO;
  33. using System.Runtime.InteropServices;
  34. using System.Security.Cryptography;
  35. using System.Security.Policy;
  36. using System.Net;
  37. using System.Text;
  38. using System.Xml;
  39. namespace System.Security.Cryptography.Xml {
  40. public class SignedXml {
  41. protected Signature m_signature;
  42. private AsymmetricAlgorithm key;
  43. protected string m_strSigningKeyName;
  44. private XmlDocument envdoc;
  45. private IEnumerator pkEnumerator;
  46. private XmlElement signatureElement;
  47. private Hashtable hashes;
  48. // FIXME: enable it after CAS implementation
  49. #if false //NET_1_1
  50. private XmlResolver xmlResolver = new XmlSecureResolver (new XmlUrlResolver (), new Evidence ());
  51. #else
  52. private XmlResolver xmlResolver = new XmlUrlResolver ();
  53. #endif
  54. private ArrayList manifests;
  55. private static readonly char [] whitespaceChars = new char [] {' ', '\r', '\n', '\t'};
  56. public SignedXml ()
  57. {
  58. m_signature = new Signature ();
  59. m_signature.SignedInfo = new SignedInfo ();
  60. hashes = new Hashtable (2); // 98% SHA1 for now
  61. }
  62. public SignedXml (XmlDocument document) : this ()
  63. {
  64. if (document == null)
  65. throw new ArgumentNullException ("document");
  66. envdoc = document;
  67. }
  68. public SignedXml (XmlElement elem) : this ()
  69. {
  70. if (elem == null)
  71. throw new ArgumentNullException ("elem");
  72. envdoc = new XmlDocument ();
  73. envdoc.LoadXml (elem.OuterXml);
  74. }
  75. public const string XmlDsigCanonicalizationUrl = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
  76. public const string XmlDsigCanonicalizationWithCommentsUrl = XmlDsigCanonicalizationUrl + "#WithComments";
  77. public const string XmlDsigNamespaceUrl = "http://www.w3.org/2000/09/xmldsig#";
  78. public const string XmlDsigDSAUrl = XmlDsigNamespaceUrl + "dsa-sha1";
  79. public const string XmlDsigHMACSHA1Url = XmlDsigNamespaceUrl + "hmac-sha1";
  80. public const string XmlDsigMinimalCanonicalizationUrl = XmlDsigNamespaceUrl + "minimal";
  81. public const string XmlDsigRSASHA1Url = XmlDsigNamespaceUrl + "rsa-sha1";
  82. public const string XmlDsigSHA1Url = XmlDsigNamespaceUrl + "sha1";
  83. public KeyInfo KeyInfo {
  84. get { return m_signature.KeyInfo; }
  85. set { m_signature.KeyInfo = value; }
  86. }
  87. public Signature Signature {
  88. get { return m_signature; }
  89. }
  90. public string SignatureLength {
  91. get { return m_signature.SignedInfo.SignatureLength; }
  92. }
  93. public string SignatureMethod {
  94. get { return m_signature.SignedInfo.SignatureMethod; }
  95. }
  96. public byte[] SignatureValue {
  97. get { return m_signature.SignatureValue; }
  98. }
  99. public SignedInfo SignedInfo {
  100. get { return m_signature.SignedInfo; }
  101. }
  102. public AsymmetricAlgorithm SigningKey {
  103. get { return key; }
  104. set { key = value; }
  105. }
  106. // NOTE: CryptoAPI related ? documented as fx internal
  107. public string SigningKeyName {
  108. get { return m_strSigningKeyName; }
  109. set { m_strSigningKeyName = value; }
  110. }
  111. public void AddObject (DataObject dataObject)
  112. {
  113. m_signature.AddObject (dataObject);
  114. }
  115. public void AddReference (Reference reference)
  116. {
  117. m_signature.SignedInfo.AddReference (reference);
  118. }
  119. private Stream ApplyTransform (Transform t, XmlDocument input)
  120. {
  121. // These transformer modify input document, which should
  122. // not affect to the input itself.
  123. if (t is XmlDsigXPathTransform ||
  124. t is XmlDsigEnvelopedSignatureTransform)
  125. input = (XmlDocument) input.Clone ();
  126. t.LoadInput (input);
  127. if (t is XmlDsigEnvelopedSignatureTransform)
  128. // It returns XmlDocument for XmlDocument input.
  129. return CanonicalizeOutput (t.GetOutput ());
  130. object obj = t.GetOutput ();
  131. if (obj is Stream)
  132. return (Stream) obj;
  133. else if (obj is XmlDocument) {
  134. MemoryStream ms = new MemoryStream ();
  135. XmlTextWriter xtw = new XmlTextWriter (ms, Encoding.UTF8);
  136. ((XmlDocument) obj).WriteTo (xtw);
  137. return ms;
  138. }
  139. else if (obj == null) {
  140. throw new NotImplementedException ("This should not occur. Transform is " + t + ".");
  141. }
  142. else {
  143. // e.g. XmlDsigXPathTransform returns XmlNodeList
  144. return CanonicalizeOutput (obj);
  145. }
  146. }
  147. private Stream CanonicalizeOutput (object obj)
  148. {
  149. Transform c14n = GetC14NMethod ();
  150. c14n.LoadInput (obj);
  151. return (Stream) c14n.GetOutput ();
  152. }
  153. private XmlDocument GetManifest (Reference r)
  154. {
  155. XmlDocument doc = new XmlDocument ();
  156. doc.PreserveWhitespace = true;
  157. if (r.Uri [0] == '#') {
  158. // local manifest
  159. if (signatureElement != null) {
  160. XmlElement xel = GetIdElement (signatureElement.OwnerDocument, r.Uri.Substring (1));
  161. if (xel == null)
  162. throw new CryptographicException ("Manifest targeted by Reference was not found: " + r.Uri.Substring (1));
  163. doc.LoadXml (xel.OuterXml);
  164. FixupNamespaceNodes (xel, doc.DocumentElement);
  165. }
  166. }
  167. else if (xmlResolver != null) {
  168. // TODO: need testing
  169. Stream s = (Stream) xmlResolver.GetEntity (new Uri (r.Uri), null, typeof (Stream));
  170. doc.Load (s);
  171. }
  172. if (doc.FirstChild != null) {
  173. // keep a copy of the manifests to check their references later
  174. if (manifests == null)
  175. manifests = new ArrayList ();
  176. manifests.Add (doc);
  177. return doc;
  178. }
  179. return null;
  180. }
  181. private void FixupNamespaceNodes (XmlElement src, XmlElement dst)
  182. {
  183. // add namespace nodes
  184. foreach (XmlAttribute attr in src.SelectNodes ("namespace::*")) {
  185. if (attr.LocalName == "xml")
  186. continue;
  187. if (attr.OwnerElement == src)
  188. continue;
  189. dst.SetAttributeNode (dst.OwnerDocument.ImportNode (attr, true) as XmlAttribute);
  190. }
  191. }
  192. [MonoTODO ("Need testing")]
  193. private byte[] GetReferenceHash (Reference r)
  194. {
  195. Stream s = null;
  196. XmlDocument doc = null;
  197. if (r.Uri == String.Empty) {
  198. doc = envdoc;
  199. }
  200. else if (r.Type == XmlSignature.Uri.Manifest) {
  201. doc = GetManifest (r);
  202. }
  203. else {
  204. doc = new XmlDocument ();
  205. doc.PreserveWhitespace = true;
  206. string objectName = null;
  207. if (r.Uri.StartsWith ("#xpointer")) {
  208. string uri = string.Join ("", r.Uri.Substring (9).Split (whitespaceChars));
  209. if (uri.Length < 2 || uri [0] != '(' || uri [uri.Length - 1] != ')')
  210. // FIXME: how to handle invalid xpointer?
  211. uri = String.Empty;
  212. else
  213. uri = uri.Substring (1, uri.Length - 2);
  214. if (uri == "/")
  215. doc = envdoc;
  216. else if (uri.Length > 6 && uri.StartsWith ("id(") && uri [uri.Length - 1] == ')')
  217. // id('foo'), id("foo")
  218. objectName = uri.Substring (4, uri.Length - 6);
  219. }
  220. else if (r.Uri [0] == '#') {
  221. objectName = r.Uri.Substring (1);
  222. }
  223. else if (xmlResolver != null) {
  224. // TODO: test but doc says that Resolver = null -> no access
  225. try {
  226. // no way to know if valid without throwing an exception
  227. Uri uri = new Uri (r.Uri);
  228. s = (Stream) xmlResolver.GetEntity (new Uri (r.Uri), null, typeof (Stream));
  229. }
  230. catch {
  231. // may still be a local file (and maybe not xml)
  232. s = File.OpenRead (r.Uri);
  233. }
  234. }
  235. if (objectName != null) {
  236. foreach (DataObject obj in m_signature.ObjectList) {
  237. if (obj.Id == objectName) {
  238. XmlElement xel = obj.GetXml ();
  239. doc.LoadXml (xel.OuterXml);
  240. FixupNamespaceNodes (xel, doc.DocumentElement);
  241. break;
  242. }
  243. }
  244. }
  245. }
  246. if (r.TransformChain.Count > 0) {
  247. foreach (Transform t in r.TransformChain) {
  248. if (s == null) {
  249. s = ApplyTransform (t, doc);
  250. }
  251. else {
  252. t.LoadInput (s);
  253. object o = t.GetOutput ();
  254. if (o is Stream)
  255. s = (Stream) o;
  256. else
  257. s = CanonicalizeOutput (o);
  258. }
  259. }
  260. }
  261. else if (s == null) {
  262. // we must not C14N references from outside the document
  263. // e.g. non-xml documents
  264. if (r.Uri [0] != '#') {
  265. s = new MemoryStream ();
  266. doc.Save (s);
  267. }
  268. else {
  269. // apply default C14N transformation
  270. s = ApplyTransform (new XmlDsigC14NTransform (), doc);
  271. }
  272. }
  273. HashAlgorithm digest = GetHash (r.DigestMethod);
  274. return digest.ComputeHash (s);
  275. }
  276. private void DigestReferences ()
  277. {
  278. // we must tell each reference which hash algorithm to use
  279. // before asking for the SignedInfo XML !
  280. foreach (Reference r in m_signature.SignedInfo.References) {
  281. // assume SHA-1 if nothing is specified
  282. if (r.DigestMethod == null)
  283. r.DigestMethod = XmlDsigSHA1Url;
  284. r.DigestValue = GetReferenceHash (r);
  285. }
  286. }
  287. private Transform GetC14NMethod ()
  288. {
  289. Transform t = (Transform) CryptoConfig.CreateFromName (m_signature.SignedInfo.CanonicalizationMethod);
  290. if (t == null)
  291. throw new CryptographicException ("Unknown Canonicalization Method {0}", m_signature.SignedInfo.CanonicalizationMethod);
  292. return t;
  293. }
  294. private Stream SignedInfoTransformed ()
  295. {
  296. Transform t = GetC14NMethod ();
  297. if (signatureElement == null) {
  298. // when creating signatures
  299. XmlDocument doc = new XmlDocument ();
  300. doc.PreserveWhitespace = true;
  301. doc.LoadXml (m_signature.SignedInfo.GetXml ().OuterXml);
  302. if (envdoc != null)
  303. foreach (XmlAttribute attr in envdoc.DocumentElement.SelectNodes ("namespace::*")) {
  304. if (attr.LocalName == "xml")
  305. continue;
  306. if (attr.Prefix == doc.DocumentElement.Prefix)
  307. continue;
  308. doc.DocumentElement.SetAttributeNode (doc.ImportNode (attr, true) as XmlAttribute);
  309. }
  310. t.LoadInput (doc);
  311. }
  312. else {
  313. // when verifying signatures
  314. // TODO - check m_signature.SignedInfo.Id
  315. XmlElement el = signatureElement.GetElementsByTagName (XmlSignature.ElementNames.SignedInfo, XmlSignature.NamespaceURI) [0] as XmlElement;
  316. StringWriter sw = new StringWriter ();
  317. XmlTextWriter xtw = new XmlTextWriter (sw);
  318. xtw.WriteStartElement (el.Prefix, el.LocalName, el.NamespaceURI);
  319. // context namespace nodes (except for "xmlns:xml")
  320. XmlNodeList nl = el.SelectNodes ("namespace::*");
  321. foreach (XmlAttribute attr in nl) {
  322. if (attr.ParentNode == el)
  323. continue;
  324. if (attr.LocalName == "xml")
  325. continue;
  326. if (attr.Prefix == el.Prefix)
  327. continue;
  328. attr.WriteTo (xtw);
  329. }
  330. foreach (XmlNode attr in el.Attributes)
  331. attr.WriteTo (xtw);
  332. foreach (XmlNode n in el.ChildNodes)
  333. n.WriteTo (xtw);
  334. xtw.WriteEndElement ();
  335. byte [] si = Encoding.UTF8.GetBytes (sw.ToString ());
  336. MemoryStream ms = new MemoryStream ();
  337. ms.Write (si, 0, si.Length);
  338. ms.Position = 0;
  339. t.LoadInput (ms);
  340. }
  341. // C14N and C14NWithComments always return a Stream in GetOutput
  342. return (Stream) t.GetOutput ();
  343. }
  344. // reuse hash - most document will always use the same hash
  345. private HashAlgorithm GetHash (string algorithm)
  346. {
  347. HashAlgorithm hash = (HashAlgorithm) hashes [algorithm];
  348. if (hash == null) {
  349. hash = HashAlgorithm.Create (algorithm);
  350. if (hash == null)
  351. throw new CryptographicException ("Unknown hash algorithm: {0}", algorithm);
  352. hashes.Add (algorithm, hash);
  353. // now ready to be used
  354. }
  355. else {
  356. // important before reusing an hash object
  357. hash.Initialize ();
  358. }
  359. return hash;
  360. }
  361. public bool CheckSignature ()
  362. {
  363. return (CheckSignatureInternal (null) != null);
  364. }
  365. private bool CheckReferenceIntegrity (ArrayList referenceList)
  366. {
  367. if (referenceList == null)
  368. return false;
  369. // check digest (hash) for every reference
  370. foreach (Reference r in referenceList) {
  371. // stop at first broken reference
  372. byte[] hash = GetReferenceHash (r);
  373. if (! Compare (r.DigestValue, hash))
  374. return false;
  375. }
  376. return true;
  377. }
  378. public bool CheckSignature (AsymmetricAlgorithm key)
  379. {
  380. if (key == null)
  381. throw new ArgumentNullException ("key");
  382. return (CheckSignatureInternal (key) != null);
  383. }
  384. private AsymmetricAlgorithm CheckSignatureInternal (AsymmetricAlgorithm key)
  385. {
  386. pkEnumerator = null;
  387. if (key != null) {
  388. // check with supplied key
  389. if (!CheckSignatureWithKey (key))
  390. return null;
  391. }
  392. else {
  393. if (Signature.KeyInfo == null)
  394. throw new CryptographicException ("At least one KeyInfo is required.");
  395. // no supplied key, iterates all KeyInfo
  396. while ((key = GetPublicKey ()) != null) {
  397. if (CheckSignatureWithKey (key)) {
  398. break;
  399. }
  400. }
  401. pkEnumerator = null;
  402. if (key == null)
  403. return null;
  404. }
  405. // some parts may need to be downloaded
  406. // so where doing it last
  407. if (!CheckReferenceIntegrity (m_signature.SignedInfo.References))
  408. return null;
  409. if (manifests != null) {
  410. // do not use foreach as a manifest could contain manifests...
  411. for (int i=0; i < manifests.Count; i++) {
  412. Manifest manifest = new Manifest ((manifests [i] as XmlDocument).DocumentElement);
  413. if (! CheckReferenceIntegrity (manifest.References))
  414. return null;
  415. }
  416. }
  417. return key;
  418. }
  419. // Is the signature (over SignedInfo) valid ?
  420. private bool CheckSignatureWithKey (AsymmetricAlgorithm key)
  421. {
  422. if (key == null)
  423. return false;
  424. SignatureDescription sd = (SignatureDescription) CryptoConfig.CreateFromName (m_signature.SignedInfo.SignatureMethod);
  425. if (sd == null)
  426. return false;
  427. AsymmetricSignatureDeformatter verifier = (AsymmetricSignatureDeformatter) CryptoConfig.CreateFromName (sd.DeformatterAlgorithm);
  428. if (verifier == null)
  429. return false;
  430. try {
  431. verifier.SetKey (key);
  432. verifier.SetHashAlgorithm (sd.DigestAlgorithm);
  433. HashAlgorithm hash = GetHash (sd.DigestAlgorithm);
  434. // get the hash of the C14N SignedInfo element
  435. MemoryStream ms = (MemoryStream) SignedInfoTransformed ();
  436. byte[] digest = hash.ComputeHash (ms);
  437. return verifier.VerifySignature (digest, m_signature.SignatureValue);
  438. }
  439. catch {
  440. // e.g. SignatureMethod != AsymmetricAlgorithm type
  441. return false;
  442. }
  443. }
  444. private bool Compare (byte[] expected, byte[] actual)
  445. {
  446. bool result = ((expected != null) && (actual != null));
  447. if (result) {
  448. int l = expected.Length;
  449. result = (l == actual.Length);
  450. if (result) {
  451. for (int i=0; i < l; i++) {
  452. if (expected[i] != actual[i])
  453. return false;
  454. }
  455. }
  456. }
  457. return result;
  458. }
  459. public bool CheckSignature (KeyedHashAlgorithm macAlg)
  460. {
  461. if (macAlg == null)
  462. throw new ArgumentNullException ("macAlg");
  463. pkEnumerator = null;
  464. // Is the signature (over SignedInfo) valid ?
  465. Stream s = SignedInfoTransformed ();
  466. if (s == null)
  467. return false;
  468. byte[] actual = macAlg.ComputeHash (s);
  469. // HMAC signature may be partial
  470. if (m_signature.SignedInfo.SignatureLength != null) {
  471. int length = actual.Length;
  472. try {
  473. // SignatureLength is in bits
  474. length = (Int32.Parse (m_signature.SignedInfo.SignatureLength) >> 3);
  475. }
  476. catch {
  477. }
  478. if (length != actual.Length) {
  479. byte[] trunked = new byte [length];
  480. Buffer.BlockCopy (actual, 0, trunked, 0, length);
  481. actual = trunked;
  482. }
  483. }
  484. if (Compare (m_signature.SignatureValue, actual)) {
  485. // some parts may need to be downloaded
  486. // so where doing it last
  487. return CheckReferenceIntegrity (m_signature.SignedInfo.References);
  488. }
  489. return false;
  490. }
  491. public bool CheckSignatureReturningKey (out AsymmetricAlgorithm signingKey)
  492. {
  493. signingKey = CheckSignatureInternal (null);
  494. return (signingKey != null);
  495. }
  496. public void ComputeSignature ()
  497. {
  498. if (key != null) {
  499. // required before hashing
  500. m_signature.SignedInfo.SignatureMethod = key.SignatureAlgorithm;
  501. DigestReferences ();
  502. AsymmetricSignatureFormatter signer = null;
  503. // in need for a CryptoConfig factory
  504. if (key is DSA)
  505. signer = new DSASignatureFormatter (key);
  506. else if (key is RSA)
  507. signer = new RSAPKCS1SignatureFormatter (key);
  508. if (signer != null) {
  509. SignatureDescription sd = (SignatureDescription) CryptoConfig.CreateFromName (m_signature.SignedInfo.SignatureMethod);
  510. HashAlgorithm hash = GetHash (sd.DigestAlgorithm);
  511. // get the hash of the C14N SignedInfo element
  512. byte[] digest = hash.ComputeHash (SignedInfoTransformed ());
  513. signer.SetHashAlgorithm ("SHA1");
  514. m_signature.SignatureValue = signer.CreateSignature (digest);
  515. }
  516. }
  517. }
  518. public void ComputeSignature (KeyedHashAlgorithm macAlg)
  519. {
  520. if (macAlg == null)
  521. throw new ArgumentNullException ("macAlg");
  522. if (macAlg is HMACSHA1) {
  523. DigestReferences ();
  524. m_signature.SignedInfo.SignatureMethod = XmlDsigHMACSHA1Url;
  525. m_signature.SignatureValue = macAlg.ComputeHash (SignedInfoTransformed ());
  526. }
  527. else
  528. throw new CryptographicException ("unsupported algorithm");
  529. }
  530. public virtual XmlElement GetIdElement (XmlDocument document, string idValue)
  531. {
  532. // this works only if there's a DTD or XSD available to define the ID
  533. XmlElement xel = document.GetElementById (idValue);
  534. if (xel == null) {
  535. // search an "undefined" ID
  536. xel = (XmlElement) document.SelectSingleNode ("//*[@Id='" + idValue + "']");
  537. }
  538. return xel;
  539. }
  540. // According to book ".NET Framework Security" this method
  541. // iterates all possible keys then return null
  542. protected virtual AsymmetricAlgorithm GetPublicKey ()
  543. {
  544. if (m_signature.KeyInfo == null)
  545. return null;
  546. if (pkEnumerator == null) {
  547. pkEnumerator = m_signature.KeyInfo.GetEnumerator ();
  548. }
  549. if (pkEnumerator.MoveNext ()) {
  550. AsymmetricAlgorithm key = null;
  551. KeyInfoClause kic = (KeyInfoClause) pkEnumerator.Current;
  552. if (kic is DSAKeyValue)
  553. key = DSA.Create ();
  554. else if (kic is RSAKeyValue)
  555. key = RSA.Create ();
  556. if (key != null) {
  557. key.FromXmlString (kic.GetXml ().InnerXml);
  558. return key;
  559. }
  560. }
  561. return null;
  562. }
  563. public XmlElement GetXml ()
  564. {
  565. return m_signature.GetXml ();
  566. }
  567. public void LoadXml (XmlElement value)
  568. {
  569. if (value == null)
  570. throw new ArgumentNullException ("value");
  571. signatureElement = value;
  572. m_signature.LoadXml (value);
  573. }
  574. #if NET_1_1
  575. [ComVisible (false)]
  576. public XmlResolver Resolver {
  577. set { xmlResolver = value; }
  578. }
  579. #endif
  580. }
  581. }