Sonata\Component\Payment\BasePaypal::encryptViaBuffer PHP Method

encryptViaBuffer() public method

Encrypt paypal information using openssl with a buffer.
public encryptViaBuffer ( $hash ) : string
$hash
return string the encrypted data
    public function encryptViaBuffer($hash)
    {
        $this->checkPaypalFiles();
        $key_file = $this->getOption('key_file');
        $cert_file = $this->getOption('cert_file');
        $paypal_cert_file = $this->getOption('paypal_cert_file');
        $openssl = $this->getOption('openssl');
        $openssl_cmd = "{$openssl} smime -sign -signer {$cert_file} -inkey {$key_file} " . "-outform der -nodetach -binary | {$openssl} smime -encrypt " . "-des3 -binary -outform pem {$paypal_cert_file}";
        if ($this->getLogger()) {
            $this->getLogger()->debug(sprintf('[BasePaypalPayment::encrypt] command line=%s', $openssl_cmd));
        }
        $descriptors = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'));
        $process = proc_open($openssl_cmd, $descriptors, $pipes);
        if (is_resource($process)) {
            foreach ($hash as $key => $value) {
                if ($value != '') {
                    fwrite($pipes[0], "{$key}={$value}\n");
                }
            }
            fflush($pipes[0]);
            fclose($pipes[0]);
            $output = '';
            while (!feof($pipes[1])) {
                $output .= fgets($pipes[1]);
            }
            fclose($pipes[1]);
            $return_value = proc_close($process);
            return $output;
        }
        if ($this->getLogger()) {
            $this->getLogger()->emergency("Encrypting paypal data failed, Command line encryption failed \n cmd={$openssl_cmd} \n hash=" . print_r($hash, 1));
        }
        throw new \RuntimeException('Encrypting paypal data failed');
    }