예제 #1
0
        /// <summary>
        /// Appends all encryption elements, such as <see cref="EncryptedKey"/> and <see cref="EncryptedData"/> elements.
        /// </summary>
        /// <param name="securityElement"></param>
        public void AppendEncryptionElements(XmlElement securityElement)
        {
            if (securityElement == null)
            {
                throw new ArgumentNullException(nameof(securityElement));
            }

            if (securityElement.OwnerDocument == null)
            {
                throw new ArgumentException(@"SecurityHeader needs to have an OwnerDocument", nameof(securityElement));
            }

            XmlDocument securityDocument = securityElement.OwnerDocument;

            // Add additional elements such as certificate references
            if (_as4EncryptedKey != null)
            {
                if (_as4EncryptedKey.SecurityTokenReference != null)
                {
                    _as4EncryptedKey.SecurityTokenReference.AppendSecurityTokenTo(securityElement, securityDocument);
                }
                _as4EncryptedKey.AppendEncryptedKey(securityElement);
            }
            else
            {
                LogManager.GetCurrentClassLogger().Warn("Appending Encryption Elements but there is no AS4 Encrypted Key set.");
            }

            AppendEncryptedDataElements(securityElement, securityDocument);
        }
예제 #2
0
            public void ThenAppendEncryptedKeySucceeds()
            {
                // Arrange
                var xmlDocument = new XmlDocument();

                xmlDocument.LoadXml(Properties.Resources.as4_encrypted_envelope);
                AS4EncryptedKey as4EncryptedKey = AS4EncryptedKey.LoadFromXmlDocument(xmlDocument);

                xmlDocument = new XmlDocument();
                XmlElement securityElement = xmlDocument.CreateElement(
                    "wsse",
                    "Security",
                    Constants.Namespaces.WssSecuritySecExt);

                // Act
                as4EncryptedKey.AppendEncryptedKey(securityElement);

                // Assert
                Assert.Equal("EncryptedKey", securityElement.FirstChild.LocalName);
            }