// // public static methods // // replaces the inputElement with the provided EncryptedData public static void ReplaceElement(XmlElement inputElement, EncryptedData encryptedData, bool content) { if (inputElement == null) { throw new ArgumentNullException("inputElement"); } if (encryptedData == null) { throw new ArgumentNullException("encryptedData"); } // First, get the XML representation of the EncryptedData object XmlElement elemED = encryptedData.GetXml(inputElement.OwnerDocument); switch (content) { case true: // remove all children of the input element Utils.RemoveAllChildren(inputElement); // then append the encrypted data as a child of the input element inputElement.AppendChild(elemED); break; case false: XmlNode parentNode = inputElement.ParentNode; // remove the input element from the containing document parentNode.ReplaceChild(elemED, inputElement); break; } }
public static void ReplaceElement(XmlElement inputElement, EncryptedData encryptedData, bool content) { if (inputElement == null) { throw new ArgumentNullException("inputElement"); } if (encryptedData == null) { throw new ArgumentNullException("encryptedData"); } XmlDocument ownerDocument = inputElement.OwnerDocument; inputElement.ParentNode.ReplaceChild(encryptedData.GetXml(ownerDocument), inputElement); }
public override XmlNode Encrypt(XmlNode node) { // Load config section to encrypt into xmlDocument instance XmlDocument doc = new XmlDocument { PreserveWhitespace = true }; doc.LoadXml(node.OuterXml); // Create Rijndael key. RijndaelManaged sessionKey = new RijndaelManaged(); sessionKey.KeySize = 256; EncryptedXml eXml = new EncryptedXml(); XmlElement elementToEncrypt = (XmlElement)node; byte[] encryptedElement = eXml.EncryptData(elementToEncrypt, sessionKey, false); EncryptedData edElement = new EncryptedData(); edElement.Type = EncryptedXml.XmlEncElementUrl; edElement.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncAES256Url); // Encrypt the session key and add it to an EncryptedKey element. EncryptedKey ek = new EncryptedKey(); byte[] encryptedKey = EncryptedXml.EncryptKey(sessionKey.Key, this.rsaKey, false); ek.CipherData = new CipherData(encryptedKey); ek.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncRSA15Url); // Set the KeyInfo element to specify the name of the RSA key. edElement.KeyInfo = new KeyInfo(); KeyInfoName kin = new KeyInfoName(); kin.Value = this.keyName; // Add the KeyInfoName element to the // EncryptedKey object. ek.KeyInfo.AddClause(kin); edElement.KeyInfo.AddClause(new KeyInfoEncryptedKey(ek)); // Add the encrypted element data to the // EncryptedData object. edElement.CipherData.CipherValue = encryptedElement; // EncryptedXml.ReplaceElement(elementToEncrypt, edElement, false); return edElement.GetXml(); }
public static void ReplaceElement(XmlElement inputElement, EncryptedData encryptedData, bool content) { if (inputElement == null) { throw new ArgumentNullException("inputElement"); } if (encryptedData == null) { throw new ArgumentNullException("encryptedData"); } XmlElement xml = encryptedData.GetXml(inputElement.OwnerDocument); switch (content) { case false: inputElement.ParentNode.ReplaceChild(xml, inputElement); return; case true: System.Security.Cryptography.Xml.Utils.RemoveAllChildren(inputElement); inputElement.AppendChild(xml); return; } }
// // public static methods // // replaces the inputElement with the provided EncryptedData public static void ReplaceElement (XmlElement inputElement, EncryptedData encryptedData, bool content) { if (inputElement == null) throw new ArgumentNullException("inputElement"); if (encryptedData == null) throw new ArgumentNullException("encryptedData"); // First, get the XML representation of the EncryptedData object XmlElement elemED = encryptedData.GetXml(inputElement.OwnerDocument); switch (content) { case true: // remove all children of the input element Utils.RemoveAllChildren(inputElement); // then append the encrypted data as a child of the input element inputElement.AppendChild(elemED); break; case false: XmlNode parentNode = inputElement.ParentNode; // remove the input element from the containing document parentNode.ReplaceChild(elemED, inputElement); break; } }
public static void ReplaceElement (XmlElement inputElement, EncryptedData encryptedData, bool content) { XmlDocument ownerDocument = inputElement.OwnerDocument; inputElement.ParentNode.ReplaceChild (encryptedData.GetXml (ownerDocument), inputElement); }
public static void ReplaceElement (XmlElement inputElement, EncryptedData encryptedData, bool content) { if (inputElement == null) throw new ArgumentNullException ("inputElement"); if (encryptedData == null) throw new ArgumentNullException ("encryptedData"); XmlDocument ownerDocument = inputElement.OwnerDocument; inputElement.ParentNode.ReplaceChild (encryptedData.GetXml (ownerDocument), inputElement); }
public static void ReplaceElement(XmlElement inputElement, EncryptedData encryptedData, bool content) { if (inputElement == null) { throw new ArgumentNullException("inputElement"); } if (encryptedData == null) { throw new ArgumentNullException("encryptedData"); } XmlElement xml = encryptedData.GetXml(inputElement.OwnerDocument); switch (content) { case false: inputElement.ParentNode.ReplaceChild(xml, inputElement); return; case true: System.Security.Cryptography.Xml.Utils.RemoveAllChildren(inputElement); inputElement.AppendChild(xml); return; } }