Build the encrypted response to send

@param string $certificate

@return MessageInterface
516796
public function buildEncrypted($certificate)
    {
        $stream = new Stream('php://temp', 'wb+');

        $content = base64_encode(
            (new Cryptography())->encrypt(
                json_encode(new MessageDecorator($this->getMessage())),
                $certificate
            )
        );

        $stream->write($content);

        return $this->getHttpMessage()
            ->withAddedHeader('Content-Type', 'text/plain')
            ->withBody($stream);
    }
625014
protected function _decrypt($encrypted) {
		$secret = $this->_hashSecret($this->_config['secret']);

		$vectorSize = strlen(base64_encode(str_repeat(" ", static::_vectorSize())));
		$vector = base64_decode(substr($encrypted, -$vectorSize));
		$data = base64_decode(substr($encrypted, 0, -$vectorSize));

		mcrypt_generic_init(static::$_resource, $secret, $vector);
		$decrypted = mdecrypt_generic(static::$_resource, $data);
		mcrypt_generic_deinit(static::$_resource);

		return unserialize(trim($decrypted));
	}
1347710
public static function encrypt($message, $key)
    {
        $md5Key = md5($key);
        
        $encrypted = mcrypt_encrypt(
            MCRYPT_RIJNDAEL_256, 
            $md5Key, 
            $message, 
            MCRYPT_MODE_CBC, 
            md5($md5Key)
        );
        
        $encoded_encryption = base64_encode($encrypted);
        return $encoded_encryption;
    }
319060
protected function encrypt(Response $response)
	{
		foreach ($response->headers->getCookies() as $key => $c)
		{
			$encrypted = $this->encrypter->encrypt($c->getValue());

			$response->headers->setCookie($this->duplicate($c, $encrypted));
		}

		return $response;
	}
497029
protected function encrypt(Response $response)
    {
        foreach ($response->headers->getCookies() as $cookie) {
            if ($this->isDisabled($cookie->getName())) {
                continue;
            }

            $response->headers->setCookie($this->duplicate(
                $cookie, $this->encrypter->encrypt($cookie->getValue(), static::serialized($cookie->getName()))
            ));
        }

        return $response;
    }
1215960
public function encodeResult($result)
	{
		$string = $this->encoder->encodeResult($result);

		return $this->encrypt($string);
	}
473593
public function createPasswordHash($password)
    {
        try {
            return $this->driverInstance->createPasswordHash($password);
        } catch (\Exception $e) {
            throw new CryptException($e->getMessage());
        }
    }
942606
protected function createMessageCrypt()
    {
        return Yii::createObject(MessageCrypt::className(), [$this->token, $this->encodingAesKey, $this->appId]);
    }
758402
public function encryptResponseWithSharedKey(
        ResponseInterface $response,
        SharedEncryptionKey $key
    ): ResponseInterface {
        $encrypted = Base64UrlSafe::encode(
            Simple::encrypt((string) $response->getBody(), $key)
        );
        return $response->withBody(
            $this->adapter->stringToStream($encrypted)
        );
    }
1213494
public function encrypt(string $message, string $key): string
    {
        $key = Key::loadFromAsciiSafeString($key);
        return 'ENC[' . self::ENCRYPTION_TYPE_DEFUSE_PHP_ENCRYPTION . ',' . Crypto::encrypt($message, $key) . ']';
    }
128072
public function onEncryptionResponsePacket(EncryptionResponsePacket $packet)
    {
        //if we don't have a verifiyToken sent yet then the packet has been sent without us sending a request, disconnect client
        if(null === $this->verifyToken) {
            $this->disconnectClient((new DisconnectPacket())->setReason('Packet received out of order'));
            return;
        }

        //get the verify token from the packet it and decrypt it using our key
        $verifyToken = $this->certificate->getPrivateKey()->decrypt($packet->getToken());

        //if it isn't the same as our token then encryption failed, disconnect the client
        if($verifyToken != $this->verifyToken) {
            $this->disconnectClient((new DisconnectPacket())->setReason('Invalid validation token'));
            return;
        }

        //decrypt the shared secret from the packet and decrypt it using our key
        $secret = $this->certificate->getPrivateKey()->decrypt($packet->getSecret());

        //enable encryption using the client generated secret
        $this->enableAES($secret);

        //generate a login hash the same as the client for the session server request
        $publicKey = $this->certificate->getPublicKey()->getPublicKey();
        $publicKey = base64_decode(substr($publicKey, 28, -26)); //cut out the start and end lines of the key
        $loginHash = $this->serverID . $secret . $publicKey;
        $loginHash = self::sha1($loginHash);

        //create a new Yggdrasil for checking against Mojang
        $yggdrasil = new DefaultYggdrasil();

        try {
            //ask Mojang if the user has sent a join request, throws exception on failure
            $response = $yggdrasil->hasJoined($this->username, $loginHash);

            //get and set the clients UUID from the response
            $this->uuid = $response->getUuid();

            //trigger the login success with the disconnect packet
            $disconnect = new DisconnectPacket();
            $this->emit('login_success', [$this, $disconnect]);

            //if no reason was set after the event then set a default
            if($disconnect->getReasonJSON() === null) {
                $disconnect->setReason("No kick reason supplied");
            }

            //disconnect the client
            $this->disconnectClient($disconnect);
        } catch (Exception $ex) {
            echo "{$this->username} failed authentication with Mojang session servers\n";
            //exception occured checking against Mojang
            $this->disconnectClient((new DisconnectPacket())->setReason("Error Authenticating with Mojang servers"));
        }
    }
32129
protected function makeRequest(string $hash): ResponseInterface
    {
        $uri = $this->getUriFactory()->createUri('https://api.pwnedpasswords.com/range/'.substr($hash, 0, 5));
        $request = $this->getRequestFactory()->createRequest('GET', $uri);

        return $this->getClient()->sendRequest($request);
    }
934767
public function receiveFeedback(Apns\Certificate $certificate = null)
	{
		$feedback = $this->feedbackFactory->createFeedback($certificate);
		$feedback->setLogger($this->logger);

		return $feedback->receive();
	}
678215
public function setEncryption($encryption)
    {
        $encryption = strtolower($encryption);
        if ('tls' == $encryption) {
            $this->params['protocol'] = 'tcp';
            $this->params['tls'] = true;
        } else {
            $this->params['protocol'] = $encryption;
            $this->params['tls'] = false;
        }

        return $this;
    }
546368
public function send(\Psr\Http\Message\RequestInterface $request)
    {
        if ($this->credentials instanceof Container) {
            if (strpos($request->getUri()->getPath(), '/v1/calls') === 0) {
                $request = $request->withHeader('Authorization', 'Bearer '.$this->credentials->get(Keypair::class)->generateJwt());
            } else {
                $request = self::authRequest($request, $this->credentials->get(Basic::class));
            }
        } elseif ($this->credentials instanceof Keypair) {
            $request = $request->withHeader('Authorization', 'Bearer '.$this->credentials->get(Keypair::class)->generateJwt());
        } elseif ($this->credentials instanceof SharedSecret) {
            $request = self::signRequest($request, $this->credentials);
        } elseif ($this->credentials instanceof Basic) {
            $request = self::authRequest($request, $this->credentials);
        }

        //todo: add oauth support

        //allow any part of the URI to be replaced with a simple search
        if (isset($this->options['url'])) {
            foreach ($this->options['url'] as $search => $replace) {
                $uri = (string) $request->getUri();

                $new = str_replace($search, $replace, $uri);
                if ($uri !== $new) {
                    $request = $request->withUri(new Uri($new));
                }
            }
        }

        $response = $this->client->sendRequest($request);

        return $response;
    }
350285
public function withSSLCert($sslCert, $sslKey)
    {
        $this->sslCert = $sslCert;
        $this->sslKey = $sslKey;

        return $this;
    }
501447
public function decryptResponse($response)
    {
        if (!is_string($response)) {
            return $response;
        }

        if ($this->usesEncryption()) {
            return json_decode(
                json_encode(
                    JWT::decode(
                        $response,
                        $this->encryptionKey,
                        array($this->encryptionAlgorithm)
                    )
                ),
                true
            );
        }

        throw EncryptionConfigurationException::undeterminedEncryption();
    }