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

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