Code Duplication    Length = 23-25 lines in 3 locations

src/SAML2/AuthnRequest.php 1 location

@@ 605-629 (lines=25) @@
602
     *
603
     * @param XMLSecurityKey $key The encryption key.
604
     */
605
    public function encryptNameId(XMLSecurityKey $key)
606
    {
607
        /* First create a XML representation of the NameID. */
608
        $doc  = new \DOMDocument();
609
        $root = $doc->createElement('root');
610
        $doc->appendChild($root);
611
        Utils::addNameId($root, $this->nameId);
612
        $nameId = $root->firstChild;
613
614
        Utils::getContainer()->debugMessage($nameId, 'encrypt');
615
616
        /* Encrypt the NameID. */
617
        $enc = new XMLSecEnc();
618
        $enc->setNode($nameId);
619
        // @codingStandardsIgnoreStart
620
        $enc->type = XMLSecEnc::Element;
621
        // @codingStandardsIgnoreEnd
622
623
        $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
624
        $symmetricKey->generateSessionKey();
625
        $enc->encryptKey($key, $symmetricKey);
626
627
        $this->encryptedNameId = $enc->encryptNode($symmetricKey);
628
        $this->nameId          = null;
629
    }
630
631
    /**
632
     * 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
        Utils::addNameId($root, $this->nameId);
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

@@ 710-734 (lines=25) @@
707
     *
708
     * @param XMLSecurityKey $key The encryption key.
709
     */
710
    public function encryptNameId(XMLSecurityKey $key)
711
    {
712
        /* First create a XML representation of the NameID. */
713
        $doc = DOMDocumentFactory::create();
714
        $root = $doc->createElement('root');
715
        $doc->appendChild($root);
716
        Utils::addNameId($root, $this->nameId);
717
        $nameId = $root->firstChild;
718
719
        Utils::getContainer()->debugMessage($nameId, 'encrypt');
720
721
        /* Encrypt the NameID. */
722
        $enc = new XMLSecEnc();
723
        $enc->setNode($nameId);
724
        // @codingStandardsIgnoreStart
725
        $enc->type = XMLSecEnc::Element;
726
        // @codingStandardsIgnoreEnd
727
728
        $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
729
        $symmetricKey->generateSessionKey();
730
        $enc->encryptKey($key, $symmetricKey);
731
732
        $this->encryptedNameId = $enc->encryptNode($symmetricKey);
733
        $this->nameId = null;
734
    }
735
736
    /**
737
     * Decrypt the NameId of the subject in the assertion.