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

@@ 746-770 (lines=25) @@
743
     *
744
     * @param XMLSecurityKey $key The encryption key.
745
     */
746
    public function encryptNameId(XMLSecurityKey $key)
747
    {
748
        /* First create a XML representation of the NameID. */
749
        $doc = DOMDocumentFactory::create();
750
        $root = $doc->createElement('root');
751
        $doc->appendChild($root);
752
        Utils::addNameId($root, $this->nameId);
753
        $nameId = $root->firstChild;
754
755
        Utils::getContainer()->debugMessage($nameId, 'encrypt');
756
757
        /* Encrypt the NameID. */
758
        $enc = new XMLSecEnc();
759
        $enc->setNode($nameId);
760
        // @codingStandardsIgnoreStart
761
        $enc->type = XMLSecEnc::Element;
762
        // @codingStandardsIgnoreEnd
763
764
        $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
765
        $symmetricKey->generateSessionKey();
766
        $enc->encryptKey($key, $symmetricKey);
767
768
        $this->encryptedNameId = $enc->encryptNode($symmetricKey);
769
        $this->nameId = null;
770
    }
771
772
    /**
773
     * Decrypt the NameId of the subject in the assertion.

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
        Utils::addNameId($root, $this->nameId);
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.