EncryptionProperty.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // EncryptionProperty.cs - EncryptionProperty implementation for XML Encryption
  3. // http://www.w3.org/2001/04/xmlenc#sec-EncryptionProperty
  4. //
  5. // Author:
  6. // Tim Coleman ([email protected])
  7. //
  8. // Copyright (C) Tim Coleman, 2004
  9. #if NET_1_2
  10. using System.Xml;
  11. namespace System.Security.Cryptography.Xml {
  12. public sealed class EncryptionProperty {
  13. #region Fields
  14. XmlElement elemProp;
  15. string id;
  16. string target;
  17. #endregion // Fields
  18. #region Constructors
  19. public EncryptionProperty ()
  20. {
  21. }
  22. public EncryptionProperty (XmlElement elemProp)
  23. {
  24. LoadXml (elemProp);
  25. }
  26. #endregion // Constructors
  27. #region Properties
  28. public string Id {
  29. get { return id; }
  30. }
  31. public XmlElement PropertyElement {
  32. get { return elemProp; }
  33. set { LoadXml (value); }
  34. }
  35. public string Target {
  36. get { return target; }
  37. }
  38. #endregion // Properties
  39. #region Methods
  40. public XmlElement GetXml ()
  41. {
  42. return GetXml (new XmlDocument ());
  43. }
  44. internal XmlElement GetXml (XmlDocument document)
  45. {
  46. XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.EncryptionProperty, EncryptedXml.XmlEncNamespaceUrl);
  47. if (Id != null)
  48. xel.SetAttribute (XmlEncryption.AttributeNames.Id, Id);
  49. if (Target != null)
  50. xel.SetAttribute (XmlEncryption.AttributeNames.Target, Target);
  51. return xel;
  52. }
  53. public void LoadXml (XmlElement value)
  54. {
  55. if (value == null)
  56. throw new ArgumentNullException ("value");
  57. if ((value.LocalName != XmlEncryption.ElementNames.EncryptionProperty) || (value.NamespaceURI != EncryptedXml.XmlEncNamespaceUrl))
  58. throw new CryptographicException ("Malformed EncryptionProperty element.");
  59. else {
  60. if (value.HasAttribute (XmlEncryption.AttributeNames.Id))
  61. this.id = value.Attributes [XmlEncryption.AttributeNames.Id].Value;
  62. if (value.HasAttribute (XmlEncryption.AttributeNames.Target))
  63. this.target = value.Attributes [XmlEncryption.AttributeNames.Target].Value;
  64. }
  65. }
  66. #endregion // Methods
  67. }
  68. }
  69. #endif