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/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.

src/SAML2/AuthnRequest.php 1 location

@@ 673-697 (lines=25) @@
670
     *
671
     * @param XMLSecurityKey $key The encryption key.
672
     */
673
    public function encryptNameId(XMLSecurityKey $key)
674
    {
675
        /* First create a XML representation of the NameID. */
676
        $doc  = new \DOMDocument();
677
        $root = $doc->createElement('root');
678
        $doc->appendChild($root);
679
        $this->nameId->toXML($root);
680
        $nameId = $root->firstChild;
681
682
        Utils::getContainer()->debugMessage($nameId, 'encrypt');
683
684
        /* Encrypt the NameID. */
685
        $enc = new XMLSecEnc();
686
        $enc->setNode($nameId);
687
        // @codingStandardsIgnoreStart
688
        $enc->type = XMLSecEnc::Element;
689
        // @codingStandardsIgnoreEnd
690
691
        $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
692
        $symmetricKey->generateSessionKey();
693
        $enc->encryptKey($key, $symmetricKey);
694
695
        $this->encryptedNameId = $enc->encryptNode($symmetricKey);
696
        $this->nameId          = null;
697
    }
698
699
    /**
700
     * Decrypt the NameId of the subject in the assertion.