Code Duplication    Length = 23-25 lines in 3 locations

src/SAML2/AuthnRequest.php 1 location

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

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/Assertion.php 1 location

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