Code Duplication    Length = 23-25 lines in 3 locations

src/SAML2/LogoutRequest.php 1 location

@@ 126-148 (lines=23) @@
123
     *
124
     * @param XMLSecurityKey $key The encryption key.
125
     */
126
    public function encryptNameId(XMLSecurityKey $key)
127
    {
128
        /* First create a XML representation of the NameID. */
129
        $doc = DOMDocumentFactory::create();
130
        $root = $doc->createElement('root');
131
        $doc->appendChild($root);
132
        $this->nameId->toXML($root);
133
        $nameId = $root->firstChild;
134
135
        Utils::getContainer()->debugMessage($nameId, 'encrypt');
136
137
        /* Encrypt the NameID. */
138
        $enc = new XMLSecEnc();
139
        $enc->setNode($nameId);
140
        $enc->type = XMLSecEnc::Element;
141
142
        $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
143
        $symmetricKey->generateSessionKey();
144
        $enc->encryptKey($key, $symmetricKey);
145
146
        $this->encryptedNameId = $enc->encryptNode($symmetricKey);
147
        $this->nameId = null;
148
    }
149
150
    /**
151
     * Decrypt the NameID in the LogoutRequest.

src/SAML2/AuthnRequest.php 1 location

@@ 617-641 (lines=25) @@
614
     *
615
     * @param XMLSecurityKey $key The encryption key.
616
     */
617
    public function encryptNameId(XMLSecurityKey $key)
618
    {
619
        /* First create a XML representation of the NameID. */
620
        $doc  = new \DOMDocument();
621
        $root = $doc->createElement('root');
622
        $doc->appendChild($root);
623
        $this->nameId->toXML($root);
624
        $nameId = $root->firstChild;
625
626
        Utils::getContainer()->debugMessage($nameId, 'encrypt');
627
628
        /* Encrypt the NameID. */
629
        $enc = new XMLSecEnc();
630
        $enc->setNode($nameId);
631
        // @codingStandardsIgnoreStart
632
        $enc->type = XMLSecEnc::Element;
633
        // @codingStandardsIgnoreEnd
634
635
        $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
636
        $symmetricKey->generateSessionKey();
637
        $enc->encryptKey($key, $symmetricKey);
638
639
        $this->encryptedNameId = $enc->encryptNode($symmetricKey);
640
        $this->nameId          = null;
641
    }
642
643
    /**
644
     * Decrypt the NameId of the subject in the assertion.

src/SAML2/Assertion.php 1 location

@@ 769-793 (lines=25) @@
766
     *
767
     * @param XMLSecurityKey $key The encryption key.
768
     */
769
    public function encryptNameId(XMLSecurityKey $key)
770
    {
771
        /* First create a XML representation of the NameID. */
772
        $doc = DOMDocumentFactory::create();
773
        $root = $doc->createElement('root');
774
        $doc->appendChild($root);
775
        $this->nameId->toXML($root);
776
        $nameId = $root->firstChild;
777
778
        Utils::getContainer()->debugMessage($nameId, 'encrypt');
779
780
        /* Encrypt the NameID. */
781
        $enc = new XMLSecEnc();
782
        $enc->setNode($nameId);
783
        // @codingStandardsIgnoreStart
784
        $enc->type = XMLSecEnc::Element;
785
        // @codingStandardsIgnoreEnd
786
787
        $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
788
        $symmetricKey->generateSessionKey();
789
        $enc->encryptKey($key, $symmetricKey);
790
791
        $this->encryptedNameId = $enc->encryptNode($symmetricKey);
792
        $this->nameId = null;
793
    }
794
795
    /**
796
     * Decrypt the NameId of the subject in the assertion.