예제 #1
0
        public void EncryptBody(XmlDocument xmlDoc)
        {
            XmlElement elementToEncrypt = xmlDoc.GetElementsByTagName("Body", "http://www.w3.org/2003/05/soap-envelope")[0] as XmlElement;

            elementToEncrypt = elementToEncrypt.FirstChild as XmlElement;
            X509Certificate2 cert = _certstore.DBEncryptionCertificate();

            // Encrypt and replace body
            EncryptedData edElement = EncryptBody(cert, elementToEncrypt);

            EncryptedXml.ReplaceElement(elementToEncrypt, edElement, false);

            // Move X509 element to correct place.
            var x509element  = xmlDoc.GetElementsByTagName("X509Data")[0];
            var encryptedKey = xmlDoc.GetElementsByTagName("KeyInfo");

            for (int i = 0; i < encryptedKey.Count; i++)
            {
                if (encryptedKey[i].ParentNode.Name.Equals("EncryptedKey"))
                {
                    encryptedKey[i].AppendChild(x509element);
                }
            }

            // Make sure the correct Xenc namespace is set (or else DataPower will reject the message)
            SetEncryptionXencNamespace(xmlDoc);
        }
 public void Can_load_db_encryption()
 {
     Assert.IsNotNull(sut.DBEncryptionCertificate());
 }