public void PropagatedNamespaces_XmlDecryptionTransform(bool addPropagatedNamespace, string expectedResult) { XmlDocument baseDocument = new XmlDocument(); baseDocument.LoadXml("<a><b><c xmlns=\"urn:foo\"/></b></a>"); using (Aes aes = Aes.Create()) { EncryptedXml encryptedXml = new EncryptedXml(baseDocument); encryptedXml.AddKeyNameMapping("key", aes); XmlElement bElement = (XmlElement)baseDocument.DocumentElement.SelectSingleNode("b"); EncryptedData encryptedData = encryptedXml.Encrypt(bElement, "key"); EncryptedXml.ReplaceElement(bElement, encryptedData, false); XmlDecryptionTransform decryptionTransform = new XmlDecryptionTransform(); decryptionTransform.EncryptedXml = encryptedXml; decryptionTransform.LoadInput(baseDocument); if (addPropagatedNamespace) { decryptionTransform.PropagatedNamespaces.Add("f", "urn:foo"); } XmlDocument decryptedDocument = (XmlDocument)decryptionTransform.GetOutput(typeof(XmlDocument)); Assert.Equal(expectedResult, decryptedDocument.OuterXml); } }
public void PropagatedNamespaces_XmlDecryptionTransform(bool addPropagatedNamespace, string expectedResult) { XmlDocument baseDocument = new XmlDocument(); baseDocument.LoadXml("<a><b><c xmlns=\"urn:foo\"/></b></a>"); var aes = CipherUtilities.GetCipher("AES/CBC/PKCS7"); var random = new SecureRandom(); var keyData = new byte[aes.GetBlockSize()]; var ivData = new byte[aes.GetBlockSize()]; random.NextBytes(ivData); random.NextBytes(keyData); var key = new ParametersWithIV(new KeyParameter(keyData), ivData); EncryptedXml encryptedXml = new EncryptedXml(baseDocument); encryptedXml.AddKeyNameMapping("key", key); XmlElement bElement = (XmlElement)baseDocument.DocumentElement.SelectSingleNode("b"); EncryptedData encryptedData = encryptedXml.Encrypt(bElement, "key"); EncryptedXml.ReplaceElement(bElement, encryptedData, false); XmlDecryptionTransform decryptionTransform = new XmlDecryptionTransform(); decryptionTransform.EncryptedXml = encryptedXml; decryptionTransform.LoadInput(baseDocument); if (addPropagatedNamespace) { decryptionTransform.PropagatedNamespaces.Add("f", "urn:foo"); } XmlDocument decryptedDocument = (XmlDocument)decryptionTransform.GetOutput(typeof(XmlDocument)); Assert.Equal(expectedResult, decryptedDocument.OuterXml); }