【问题标题】:Paypal development. encrypt transactions. php p12支付宝开发。加密交易。 php p12
【发布时间】:2014-07-17 10:35:36
【问题描述】:

当我查看 paypal 文档时,他们说“请注意,用于 PHP 的 PayPal SDK 不需要 SSL 加密”。 https://developer.paypal.com/docs/classic/api/apiCredentials/#encrypting-your-certificate

这句话的意思是说我在使用php时不必创建p12证书,而是使用public_key.pempaypal_public_key.pem

如果是: 在没有 p12 证书的情况下创建加密的表单输入元素是否足够安全?

如果没有: 他们的意思是什么? :-)

在提出这个问题之前,我已经测试了这个小程序。 http://www.softarea51.com/blog/how-to-integrate-your-custom-shopping-cart-with-paypal-website-payments-standard-using-php/

有一个配置文件 paypal-wps-config.inc.php 我可以在其中定义我的证书的路径。

  // tryed to use // 'paypal_cert.p12 ';
  $config['private_key_path'] = '/home/folder/.cert/pp/prvkey.pem'; 

  // must match the one you set when you created the private key
  $config['private_key_password'] = ''; //'my_password'; 

当我尝试使用 p12 证书时,openssl_error_string() 返回“无法签署数据:错误:0906D06C:PEM 例程:PEM_read_bio:no start line openssl_pkcs7_sign

当我改为使用没有密码的 prvkey.pem 时,一切正常。

这是对数据进行签名和加密的函数。

    function signAndEncrypt($dataStr_, $ewpCertPath_, $ewpPrivateKeyPath_, $ewpPrivateKeyPwd_, $paypalCertPath_)
    {

        $dataStrFile  = realpath(tempnam('/tmp', 'pp_'));
        $fd = fopen($dataStrFile, 'w');
        if(!$fd) {
            $error = "Could not open temporary file $dataStrFile.";
            return array("status" => false, "error_msg" => $error, "error_no" => 0);
        }
        fwrite($fd, $dataStr_);
        fclose($fd);

        $signedDataFile = realpath(tempnam('/tmp', 'pp_'));
        **// here the error came from**
        if(!@openssl_pkcs7_sign(    $dataStrFile,
                                    $signedDataFile,
                                    "file://$ewpCertPath_",
                                    array("file://$ewpPrivateKeyPath_", $ewpPrivateKeyPwd_),
                                    array(),
                                    PKCS7_BINARY)) {
            unlink($dataStrFile);
            unlink($signedDataFile);
            $error = "Could not sign data: ".openssl_error_string();
            return array("status" => false, "error_msg" => $error, "error_no" => 0);
        }

        unlink($dataStrFile);

        $signedData = file_get_contents($signedDataFile);
        $signedDataArray = explode("\n\n", $signedData);
        $signedData = $signedDataArray[1];
        $signedData = base64_decode($signedData);

        unlink($signedDataFile);

        $decodedSignedDataFile = realpath(tempnam('/tmp', 'pp_'));
        $fd = fopen($decodedSignedDataFile, 'w');
        if(!$fd) {
            $error = "Could not open temporary file $decodedSignedDataFile.";
            return array("status" => false, "error_msg" => $error, "error_no" => 0);
        }
        fwrite($fd, $signedData);
        fclose($fd);

        $encryptedDataFile = realpath(tempnam('/tmp', 'pp_'));
        if(!@openssl_pkcs7_encrypt( $decodedSignedDataFile,
                                    $encryptedDataFile,
                                    file_get_contents($paypalCertPath_),
                                    array(),
                                    PKCS7_BINARY)) {
            unlink($decodedSignedDataFile);
            unlink($encryptedDataFile);
            $error = "Could not encrypt data: ".openssl_error_string();
            return array("status" => false, "error_msg" => $error, "error_no" => 0);
        }

        unlink($decodedSignedDataFile);

        $encryptedData = file_get_contents($encryptedDataFile);
        if(!$encryptedData) {
            $error = "Encryption and signature of data failed.";
            return array("status" => false, "error_msg" => $error, "error_no" => 0);
        }

        unlink($encryptedDataFile);

        $encryptedDataArray = explode("\n\n", $encryptedData);
        $encryptedData = trim(str_replace("\n", '', $encryptedDataArray[1]));

        return array("status" => true, "encryptedData" => $encryptedData);
    } // signAndEncrypt
} // PPCrypto

主要问题:

  1. 是否可以将 p12 证书与 php 一起使用,或者没有它是否足够安全?

  2. 为什么我在使用openssl_pkcs7_sign时会报错

请帮忙。

问候 宁辰

【问题讨论】:

    标签: php ssl encryption paypal certificate


    【解决方案1】:

    您不应将“使用 SSL”与“使用带有预定义客户端证书的 SSL”混淆。您链接到的文档描述了后者。只需调用https URL 即可启用 SSL 并提供与浏览器等效的安全性。这是由 SDK 自动完成的。

    预定义的客户端证书可防止老练的攻击者执行中间人攻击。这两种方法都可以阻止不成熟的攻击者直接读取您的网络流量。

    客户端证书还用于向 PayPal 验证您的身份,作为用户/密码/签名的替代。

    【讨论】:

    • 嘿汤姆。谢谢你的建议。
    • 但我还有一些问题here ---
    猜你喜欢
    • 2014-06-13
    • 1970-01-01
    • 2011-03-29
    • 2014-11-27
    • 2015-07-28
    • 2016-03-17
    • 2011-05-23
    • 2021-12-19
    • 2011-10-08
    相关资源
    最近更新 更多