private function addEncryptedAttributeStatement(DOMElement $root) : void
    {
        if ($this->getRequiredEncAttributes() === false) {
            return;
        }
        Assert::notNull($this->encryptionKey);

        $document = $root->ownerDocument;

        $attributeStatement = $document->createElementNS(Constants::NS_SAML, 'saml:AttributeStatement');
        $root->appendChild($attributeStatement);

        foreach ($this->attributes as $name => $values) {
            $document2 = DOMDocumentFactory::create();
            $attribute = $document2->createElementNS(Constants::NS_SAML, 'saml:Attribute');
            $attribute->setAttribute('Name', $name);
            $document2->appendChild($attribute);

            if ($this->nameFormat !== Constants::NAMEFORMAT_UNSPECIFIED) {
                $attribute->setAttribute('NameFormat', $this->getAttributeNameFormat());
            }

            foreach ($values as $value) {
                if (is_string($value)) {
                    $type = 'xs:string';
                } elseif (is_int($value)) {
                    $type = 'xs:integer';
                } else {
                    $type = null;
                }

                $attributeValue = $document2->createElementNS(Constants::NS_SAML, 'saml:AttributeValue');
                $attribute->appendChild($attributeValue);
                if ($type !== null) {
                    $attributeValue->setAttributeNS(Constants::NS_XSI, 'xsi:type', $type);
                }

                if ($value instanceof DOMNodeList) {
                    foreach ($value as $v) {
                        $node = $document2->importNode($v, true);
                        $attributeValue->appendChild($node);
                    }
                } else {
                    $value = strval($value);
                    $attributeValue->appendChild($document2->createTextNode($value));
                }
            }
            /*Once the attribute nodes are built, the are encrypted*/
            $EncAssert = new XMLSecEnc();
            $EncAssert->setNode($document2->documentElement);
            $EncAssert->type = 'http://www.w3.org/2001/04/xmlenc#Element';
            /*
             * Attributes are encrypted with a session key and this one with
             * $EncryptionKey
             */
            $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES256_CBC);
            $symmetricKey->generateSessionKey();
            /** @psalm-suppress PossiblyNullArgument */
            $EncAssert->encryptKey($this->encryptionKey, $symmetricKey);
            /** @psalm-suppress UndefinedClass */
            $EncrNode = $EncAssert->encryptNode($symmetricKey);

            $EncAttribute = $document->createElementNS(Constants::NS_SAML, 'saml:EncryptedAttribute');
            $attributeStatement->appendChild($EncAttribute);
            /** @psalm-suppress InvalidArgument */
            $n = $document->importNode($EncrNode, true);
            $EncAttribute->appendChild($n);
        }
    }
private function addEncryptedAttributeStatement(DOMElement $root) : void
    {
        if ($this->getRequiredEncAttributes() === false) {
            return;
        }
        Assert::notNull($this->encryptionKey);

        $document = $root->ownerDocument;

        $attributeStatement = $document->createElementNS(Constants::NS_SAML, 'saml:AttributeStatement');
        $root->appendChild($attributeStatement);

        foreach ($this->attributes as $name => $values) {
            $document2 = DOMDocumentFactory::create();
            $attribute = $document2->createElementNS(Constants::NS_SAML, 'saml:Attribute');
            $attribute->setAttribute('Name', $name);
            $document2->appendChild($attribute);

            if ($this->nameFormat !== Constants::NAMEFORMAT_UNSPECIFIED) {
                $attribute->setAttribute('NameFormat', $this->getAttributeNameFormat());
            }

            foreach ($values as $value) {
                if (is_string($value)) {
                    $type = 'xs:string';
                } elseif (is_int($value)) {
                    $type = 'xs:integer';
                } else {
                    $type = null;
                }

                $attributeValue = $document2->createElementNS(Constants::NS_SAML, 'saml:AttributeValue');
                $attribute->appendChild($attributeValue);
                if ($type !== null) {
                    $attributeValue->setAttributeNS(Constants::NS_XSI, 'xsi:type', $type);
                }

                if ($value instanceof DOMNodeList) {
                    foreach ($value as $v) {
                        $node = $document2->importNode($v, true);
                        $attributeValue->appendChild($node);
                    }
                } else {
                    $value = strval($value);
                    $attributeValue->appendChild($document2->createTextNode($value));
                }
            }
            /*Once the attribute nodes are built, the are encrypted*/
            $EncAssert = new XMLSecEnc();
            $EncAssert->setNode($document2->documentElement);
            $EncAssert->type = 'http://www.w3.org/2001/04/xmlenc#Element';
            /*
             * Attributes are encrypted with a session key and this one with
             * $EncryptionKey
             */
            $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES256_CBC);
            $symmetricKey->generateSessionKey();
            /** @psalm-suppress PossiblyNullArgument */
            $EncAssert->encryptKey($this->encryptionKey, $symmetricKey);
            /** @psalm-suppress UndefinedClass */
            $EncrNode = $EncAssert->encryptNode($symmetricKey);

            $EncAttribute = $document->createElementNS(Constants::NS_SAML, 'saml:EncryptedAttribute');
            $attributeStatement->appendChild($EncAttribute);
            /** @psalm-suppress InvalidArgument */
            $n = $document->importNode($EncrNode, true);
            $EncAttribute->appendChild($n);
        }
    }
private function addEncryptedAttributeStatement ( DOMElement $ root ) : void { if ( $ this -> getRequiredEncAttributes ( ) === false ) { return ; } Assert :: notNull ( $ this -> encryptionKey ) ; $ document = $ root -> ownerDocument ; $ attributeStatement = $ document -> createElementNS ( Constants :: NS_SAML , 'saml:AttributeStatement' ) ; $ root -> appendChild ( $ attributeStatement ) ; foreach ( $ this -> attributes as $ name => $ values ) { $ document2 = DOMDocumentFactory :: create ( ) ; $ attribute = $ document2 -> createElementNS ( Constants :: NS_SAML , 'saml:Attribute' ) ; $ attribute -> setAttribute ( 'Name' , $ name ) ; $ document2 -> appendChild ( $ attribute ) ; if ( $ this -> nameFormat !== Constants :: NAMEFORMAT_UNSPECIFIED ) { $ attribute -> setAttribute ( 'NameFormat' , $ this -> getAttributeNameFormat ( ) ) ; } foreach ( $ values as $ value ) { if ( is_string ( $ value ) ) { $ type = 'xs:string' ; } elseif ( is_int ( $ value ) ) { $ type = 'xs:integer' ; } else { $ type = null ; } $ attributeValue = $ document2 -> createElementNS ( Constants :: NS_SAML , 'saml:AttributeValue' ) ; $ attribute -> appendChild ( $ attributeValue ) ; if ( $ type !== null ) { $ attributeValue -> setAttributeNS ( Constants :: NS_XSI , 'xsi:type' , $ type ) ; } if ( $ value instanceof DOMNodeList ) { foreach ( $ value as $ v ) { $ node = $ document2 -> importNode ( $ v , true ) ; $ attributeValue -> appendChild ( $ node ) ; } } else { $ value = strval ( $ value ) ; $ attributeValue -> appendChild ( $ document2 -> createTextNode ( $ value ) ) ; } } /*Once the attribute nodes are built, the are encrypted*/ $ EncAssert = new XMLSecEnc ( ) ; $ EncAssert -> setNode ( $ document2 -> documentElement ) ; $ EncAssert -> type = 'http://www.w3.org/2001/04/xmlenc#Element' ; /*
             * Attributes are encrypted with a session key and this one with
             * $EncryptionKey
             */ $ symmetricKey = new XMLSecurityKey ( XMLSecurityKey :: AES256_CBC ) ; $ symmetricKey -> generateSessionKey ( ) ; /** @psalm-suppress PossiblyNullArgument */ $ EncAssert -> encryptKey ( $ this -> encryptionKey , $ symmetricKey ) ; /** @psalm-suppress UndefinedClass */ $ EncrNode = $ EncAssert -> encryptNode ( $ symmetricKey ) ; $ EncAttribute = $ document -> createElementNS ( Constants :: NS_SAML , 'saml:EncryptedAttribute' ) ; $ attributeStatement -> appendChild ( $ EncAttribute ) ; /** @psalm-suppress InvalidArgument */ $ n = $ document -> importNode ( $ EncrNode , true ) ; $ EncAttribute -> appendChild ( $ n ) ; } }
Add an EncryptedAttribute Statement-node to the assertion.

@param \DOMElement $root The assertion element we should add the Encrypted Attribute Statement to.
@return void
Add an EncryptedAttribute Statement - node to the assertion .