@param resource          $source
@param resource          $sin
@param VirgilPublicKey[] $recipientsPublicKeys

@throws VirgilCryptoException
193627
public function encryptStream($source, $sin, array $recipientsPublicKeys)
    {
        try {
            $cipher = $this->cryptoService->createStreamCipher();
            $cipherInputOutput = $cipher->createInputOutput($source, $sin);

            foreach ($recipientsPublicKeys as $recipientPublicKey) {
                $cipher->addKeyRecipient(
                    $recipientPublicKey->getReceiverID(),
                    $recipientPublicKey->getValue()
                );
            }

            $cipher->encrypt($cipherInputOutput);
        } catch (Exception $exception) {
            throw new VirgilCryptoException($exception->getMessage());
        }
    }
534089
public static function create(string $template, $recipients, Address $sender = null)
    {
        $email = new static($template);

        $recipients = is_array($recipients) ? $recipients : [$recipients];
        foreach ($recipients as $recipient) {
            $email->addRecipient($recipient);
        }

        if (null !== $sender) {
            $email->setSender($sender);
        }

        return $email;
    }
180486
public function create($providerKey, array $attributes, $user, SamlSpResponseToken $responseToken)
    {
        $token = new SamlSpToken(
            $user instanceof UserInterface ? $user->getRoles() : [],
            $providerKey,
            $attributes,
            $user
        );

        return $token;
    }
1339984
public function exportPrivateKey(VirgilPrivateKey $privateKey, $password = '')
    {
        try {
            return $this->cryptoService->privateKeyToDer($privateKey->getValue(), $password);
        } catch (Exception $exception) {
            throw new VirgilCryptoException($exception->getMessage());
        }
    }
882822
public function pfMerge($destinationKey, $sourceKey, ...$sourceKeys) {
        return $this->send(array_merge(['pfmerge', $destinationKey], (array) $sourceKey, $sourceKeys));
    }
53540
public function encrypt($content, array $recipientsPublicKeys)
    {
        try {
            $cipher = $this->cryptoService->createCipher();
            $cipherInputOutput = $cipher->createInputOutput($content);

            foreach ($recipientsPublicKeys as $recipientPublicKey) {
                $cipher->addKeyRecipient(
                    $recipientPublicKey->getReceiverID(),
                    $recipientPublicKey->getValue()
                );
            }

            return $cipher->encrypt($cipherInputOutput);
        } catch (Exception $exception) {
            throw new VirgilCryptoException($exception->getMessage());
        }
    }
608649
public function run(array $notification, array $variables = null, array $recipients = null)
    {
        $typeName = Arr::get($notification, 'type.name');

        switch ($typeName) {
            case 'email':
                $instance = app(EmailNotification::class);
                break;
            case 'sms':
                $instance = app(SmsNotification::class);
                break;
            default:
                $instance = app(CustomNotification::class);
                break;
        }
        $instance->setPredefinedVariables($variables);
        $instance->setModel($notification);

        if ($instance instanceof SendableNotification) {
            $instance->setRecipients($recipients);

            if (!$this->validate($instance)) {
                return false;
            }
            $type = $instance->getType();
            $job  = $instance->onConnection('database')->onQueue($type);
            $this->dispatch($job);
        } else {
            return $instance->handle();
        }
    }
1265771
public function presign(
        RequestInterface $request,
        CredentialsInterface $credentials,
        $expires
    ) {
        /*
         * Don't send this imcompatible header
         */
        //if (!$request->hasHeader('x-amz-content-sha256')) {
        //    $request = $request->withHeader(
        //        'X-Amz-Content-Sha256',
        //        $this->getPresignedPayload($request)
        //    );
        //}

        return parent::presign($request, $credentials, $expires);
    }
1235121
public function generateKeys($keyPairType = null)
    {
        try {
            if ($keyPairType == null) {
                $keyPairType = $this->keyPairType;
            }
            $keyPair = $this->cryptoService->generateKeyPair($keyPairType);

            $publicKeyDerEncoded = $this->cryptoService->publicKeyToDer($keyPair[0]);
            $privateKeyDerEncoded = $this->cryptoService->privateKeyToDer($keyPair[1]);

            $receiverID = $this->calculateFingerprint($publicKeyDerEncoded);

            $virgilPublicKey = new VirgilPublicKey($receiverID, $publicKeyDerEncoded);
            $virgilPrivateKey = new VirgilPrivateKey($receiverID, $privateKeyDerEncoded);

            return new VirgilKeyPair($virgilPublicKey, $virgilPrivateKey);
        } catch (Exception $exception) {
            throw new VirgilCryptoException($exception->getMessage());
        }
    }
962760
public function loadAndDecryptWithKeySet(string $token, JWKSet $keyset, ?int &$recipient): JWE
    {
        try {
            $jwe = $this->serializerManager->unserialize($token);
            $nbRecipients = $jwe->countRecipients();
            for ($i = 0; $i < $nbRecipients; ++$i) {
                if ($this->processRecipient($jwe, $keyset, $i)) {
                    $recipient = $i;

                    return $jwe;
                }
            }
        } catch (\Exception $e) {
            // Nothing to do. Exception thrown just after
        }

        throw new \Exception('Unable to load and decrypt the token.');
    }
236781
public function call($hostname, $source, $destination, array $config = [])
    {
        $defaults = [
            'timeout' => null,
            'options' => [],
        ];
        $config = array_merge($defaults, $config);

        $escapedSource = escapeshellarg($source);
        $escapedDestination = escapeshellarg($destination);
        $rsync = "rsync -azP " . implode(' ', $config['options']) . " $escapedSource $escapedDestination";

        $this->pop->command($hostname, $rsync);

        $process = new Process($rsync);
        $process
            ->setTimeout($config['timeout'])
            ->mustRun($this->pop->callback($hostname));
    }
819963
public function sendTo(Recipient $recipient, MessageInterface $message)
    {
        $driver = "\\Eyewitness\\Eye\\Notifications\\Drivers\\".ucfirst(strtolower($recipient->type));

        if (class_exists($driver)) {
            $channel = app($driver);
            $channel->fire($recipient, $message);
        } else {
            app(Eye::class)->logger()->debug('Notification Driver does not exist', $driver);
        }
    }
922203
public function encrypt(PushNotification $notification, Subscription $subscription) : Cipher
    {
        $plainText = $this->addPadding($notification->json());

        $recipientPublicKey = $subscription->getPublicKey();
        $authenticationSecret = $subscription->getAuthenticationSecret();

        $generator = new KeyGenerator();
        $keyPair = $generator->generateKeyPair();
        $senderPrivateKey = $keyPair->getPrivateKey();
        $senderPublicKey = $keyPair->getPublicKey();

        $sharedSecret = $senderPrivateKey->calculateSharedSecret($recipientPublicKey);

        $salt = new Salt();
        $info = new Info($recipientPublicKey, $senderPublicKey);
        $hkdf = new HKDF();

        $pseudoRandomKey = new PseudoRandomKey($hkdf($authenticationSecret, $sharedSecret, $info->getContentEncoding('auth'), 32));
        $contentEncryptionKey = new ContentEncryptionKey($hkdf($salt, $pseudoRandomKey, $info->getContentEncoding('aesgcm'), 16));
        $nonce = new Nonce($hkdf($salt, $pseudoRandomKey, $info->getContentEncoding('nonce'), 12));

        return $this->crypt->encrypt($plainText, $contentEncryptionKey, $nonce, $salt, $senderPublicKey);
    }
707066
public function sendMime(string $domain, array $recipients, string  $message, array $params)
    {
        Assert::string($domain);
        Assert::notEmpty($domain);
        Assert::notEmpty($recipients);
        Assert::notEmpty($message);
        Assert::nullOrIsArray($params);

        $params['to'] = $recipients;
        $postDataMultipart = $this->prepareMultipartParameters($params);

        if (strlen($message) < PHP_MAXPATHLEN && is_file($message)) {
            $fileData = ['filePath' => $message];
        } else {
            $fileData = [
                'fileContent' => $message,
                'filename' => 'message',
            ];
        }
        $postDataMultipart[] = $this->prepareFile('message', $fileData);
        $response = $this->httpPostRaw(sprintf('/v3/%s/messages.mime', $domain), $postDataMultipart);
        $this->closeResources($postDataMultipart);

        return $this->hydrateResponse($response, SendResponse::class);
    }
1227915
public function decryptJsonRequestWithSharedKey(
        RequestInterface $request,
        SharedEncryptionKey $key
    ): array {
        $decrypted = $this->decryptRequestWithSharedKey(
            $request,
            $key
        );

        /** @var array|bool $array */
        $array = \json_decode(
            (string) $decrypted->getBody(),
            true
        );
        if (!\is_array($array)) {
            throw new InvalidMessageException('Could not decode JSON');
        }
        return $array;
    }
182792
protected function executeOAuth2($method, $ressource, array $params = array())
	{
		$this->headers['authorization'] = sprintf('Authorization: Bearer %s', $this->getAccessToken());
		// We don't need auth since we are using an access token
		$this->enableAuth = false;
		try
		{
			$result = $this->execute($method, $ressource, $params);
			$this->enableAuth = true;
			return $result;
		}
		catch(Exception $e)
		{
			$this->enableAuth = true;
			throw $e;
		}
	}
802657
protected function createPasswordClient(ClientRepository $clients)
    {
        $name = $this->option('name') ?: $this->ask(
            'What should we name the password grant client?',
            config('app.name').' Password Grant Client'
        );

        $client = $clients->createPasswordGrantClient(
            null, $name, 'http://localhost'
        );

        $this->info('Password grant client created successfully.');

        $this->outputClientDetails($client);
    }