public function encryptViaFile($hash)
    {
        $this->checkPaypalFiles();

        $key_file = $this->getOption('key_file');
        $cert_file = $this->getOption('cert_file');
        $openssl = $this->getOption('openssl');
        $paypal_cert_file = $this->getOption('paypal_cert_file');

        // create tmp file
        $filename = tempnam(sys_get_temp_dir(), 'sonata_paypal_');
        $contents = '';
        foreach ($hash as $name => $value) {
            $contents .= $name.'='.$value."\n";
        }

        if (!@file_put_contents($filename, $contents)) {
            if ($this->getLogger()) {
                $this->getLogger()->emergency(sprintf('encryptViaFile, unable to create buffer file : %s', $filename));
            }

            throw new \RuntimeException(sprintf('unable to create buffer file : %s', $filename));
        }

        $openssl_cmd = "$openssl smime -sign -signer $cert_file -inkey $key_file -outform der -nodetach -binary ".
            " < $filename ".
            " | $openssl smime -encrypt ".
            "-des3 -binary -outform pem $paypal_cert_file";

        if ($this->getLogger()) {
            $this->getLogger()->debug(sprintf('[BasePaypalPayment::encryptViaFile] command line=%s', $openssl_cmd));
        }

        $output = shell_exec($openssl_cmd);

        if (!@unlink($filename)) {
            if ($this->getLogger()) {
                $this->getLogger()->emergency(sprintf('[BasePaypalPayment::encryptViaFile] unable to delete temporary file, %s', $filename));
            }
        }

        return $output;
    }
public function encryptViaFile($hash)
    {
        $this->checkPaypalFiles();

        $key_file = $this->getOption('key_file');
        $cert_file = $this->getOption('cert_file');
        $openssl = $this->getOption('openssl');
        $paypal_cert_file = $this->getOption('paypal_cert_file');

        // create tmp file
        $filename = tempnam(sys_get_temp_dir(), 'sonata_paypal_');
        $contents = '';
        foreach ($hash as $name => $value) {
            $contents .= $name.'='.$value."\n";
        }

        if (!@file_put_contents($filename, $contents)) {
            if ($this->getLogger()) {
                $this->getLogger()->emergency(sprintf('encryptViaFile, unable to create buffer file : %s', $filename));
            }

            throw new \RuntimeException(sprintf('unable to create buffer file : %s', $filename));
        }

        $openssl_cmd = "$openssl smime -sign -signer $cert_file -inkey $key_file -outform der -nodetach -binary ".
            " < $filename ".
            " | $openssl smime -encrypt ".
            "-des3 -binary -outform pem $paypal_cert_file";

        if ($this->getLogger()) {
            $this->getLogger()->debug(sprintf('[BasePaypalPayment::encryptViaFile] command line=%s', $openssl_cmd));
        }

        $output = shell_exec($openssl_cmd);

        if (!@unlink($filename)) {
            if ($this->getLogger()) {
                $this->getLogger()->emergency(sprintf('[BasePaypalPayment::encryptViaFile] unable to delete temporary file, %s', $filename));
            }
        }

        return $output;
    }
public function encryptViaFile ( $ hash ) { $ this -> checkPaypalFiles ( ) ; $ key_file = $ this -> getOption ( 'key_file' ) ; $ cert_file = $ this -> getOption ( 'cert_file' ) ; $ openssl = $ this -> getOption ( 'openssl' ) ; $ paypal_cert_file = $ this -> getOption ( 'paypal_cert_file' ) ; // create tmp file $ filename = tempnam ( sys_get_temp_dir ( ) , 'sonata_paypal_' ) ; $ contents = '' ; foreach ( $ hash as $ name => $ value ) { $ contents .= $ name . '=' . $ value . "\n" ; } if ( ! @ file_put_contents ( $ filename , $ contents ) ) { if ( $ this -> getLogger ( ) ) { $ this -> getLogger ( ) -> emergency ( sprintf ( 'encryptViaFile, unable to create buffer file : %s' , $ filename ) ) ; } throw new \ RuntimeException ( sprintf ( 'unable to create buffer file : %s' , $ filename ) ) ; } $ openssl_cmd = "$openssl smime -sign -signer $cert_file -inkey $key_file -outform der -nodetach -binary " . " < $filename " . " | $openssl smime -encrypt " . "-des3 -binary -outform pem $paypal_cert_file" ; if ( $ this -> getLogger ( ) ) { $ this -> getLogger ( ) -> debug ( sprintf ( '[BasePaypalPayment::encryptViaFile] command line=%s' , $ openssl_cmd ) ) ; } $ output = shell_exec ( $ openssl_cmd ) ; if ( ! @ unlink ( $ filename ) ) { if ( $ this -> getLogger ( ) ) { $ this -> getLogger ( ) -> emergency ( sprintf ( '[BasePaypalPayment::encryptViaFile] unable to delete temporary file, %s' , $ filename ) ) ; } } return $ output ; }
Encrypt paypal information using openssl with a temporary file.


@param $hash

@throws \RuntimeException

@return string the encrypted data
Encrypt paypal information using openssl with a temporary file .