动态 Paypal 按钮加密

发布于 2024-09-30 18:16:31 字数 182 浏览 1 评论 0原文

我正在使用 PHP 和 PHP 设计一个订单网站。 mysql。在最后阶段,用户将获得 Paypal 按钮来支付他所下的订单。因此,项目名称、值是变量。 这些值是变量,我无法使用 Paypal 的加密按钮。我必须使用非加密按钮或在将其显示给用户之前对其进行加密。

出于安全原因我希望对其进行加密。我想知道如何在我的服务器上执行此操作。

I'm designing a Order Site using PHP & Mysql. In the final stage the user is given Paypal buttons to pay for the Orders he has made. So, the Item Name, Value are variables.
These values being variables, I cannot use an encrypted button from Paypal. I'll have to use either a non-encrypted button or encrypt it before showing it to the user.

I wish to encrypt it for security reasons. I would like to know how to do it on my server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

花心好男孩 2024-10-07 18:16:31

您需要做的事情相当复杂,首先,intro、paypal 加密按钮具有以下布局:

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIIEQYJKo...Encrypted stuff...IF5ioje8JH0LAA+5U7P+tabAMOL37k=-----END PKCS7-----">
<input type="image" src="https://www.paypalobjects.com/es_XC/MX/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal, la forma más segura y rápida de pagar en línea.">
<img alt="" border="0" src="https://www.paypalobjects.com/es_XC/i/scr/pixel.gif" width="1" height="1">
    </form>

cmd 字段表示加密的 Buy Now 按钮(检查您要创建的按钮的值),加密字段是按钮的实际内容采用以下布局:

    cert_id=ZQCMJTZS27U4F
    cmd=_xclick
    [email protected]
    item_name=Handheld Computer
    item_number=1234
    custom=sc-id-789
    amount=500.00
    currency_code=USD
    tax=41.25
    shipping=20.00
    no_note=1
    cancel_return=http://www.company.com/cancel.htm 

注意,这些内容采用pair=value格式,有关完整参考,请参见此处:https://cms.paypal.com/us/cgi-bin /?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables

现在理论上来说,要获得加密良好的加密字段,您需要使用您的证书(x509 证书)和私钥对这些值进行签名,然后您需要使用 paypal 的公共证书加密此签名消息。

进入实践阶段,您可以(需要)使用以下两个 PHP 函数(OpenSSL 扩展的一部分):openssl_pkcs7_sign 和 openssl_pkcs7_encrypt。

我发现最后一部分设置起来非常棘手,因此我建议您在此处下载适用于 PayPal 的 PHP SDK:https://www.x.com/community/ppx/sdks#WPST 并直接在此处:https://cms .paypal.com/cms_content/US/en_US/files/developer/PP_PHP_WPS_Toolkit.zip,此 SDK 附带 EWPServices 类,该类包含 encryptButton 方法,可以非常轻松地为您提供加密按钮;如果您想查看骨骼,请查看 PPCrypto 类,该类为您提供了 signAndEncrypt 方法,该方法仅提供该字段所需的加密字符串,并显示加密按钮的过程。

顺便说一句,如果您不知道如何获取证书和私钥(和/或 Paypal 的证书),请查看此处:https://cms.paypal.com/us/cgi -bin/?cmd=_render-content&content_ID=developer/e_howto_html_encryptedweb payments#id08A3I0N30Y4

What you need to do is fairly complex, first, the intro, paypal encrypted buttons have the following layout:

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIIEQYJKo...Encrypted stuff...IF5ioje8JH0LAA+5U7P+tabAMOL37k=-----END PKCS7-----">
<input type="image" src="https://www.paypalobjects.com/es_XC/MX/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal, la forma más segura y rápida de pagar en línea.">
<img alt="" border="0" src="https://www.paypalobjects.com/es_XC/i/scr/pixel.gif" width="1" height="1">
    </form>

The cmd field indicates an encrypted Buy Now button (check the values for the buttons you want to create), and the encrypted field is the actual content of the button in the following layout:

    cert_id=ZQCMJTZS27U4F
    cmd=_xclick
    [email protected]
    item_name=Handheld Computer
    item_number=1234
    custom=sc-id-789
    amount=500.00
    currency_code=USD
    tax=41.25
    shipping=20.00
    no_note=1
    cancel_return=http://www.company.com/cancel.htm 

Note, these are in the pair=value format, for a full reference look here: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables.

Now the theory, to get the encrypted field, well encrypted, you need to sign these values with your certificate (x509 certificate) and you private key, then you need to encrypt this signed message with paypal's public certificate.

Going to the practice, for doing it you can (need) to use the following two PHP functions (part of the OpenSSL extension): openssl_pkcs7_sign and openssl_pkcs7_encrypt.

I found this last part very tricky to setup, so i recommend you to download the PHP SDK for PayPal avalaible here: https://www.x.com/community/ppx/sdks#WPST and directly here: https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_PHP_WPS_Toolkit.zip, this SDK comes with the class EWPServices who contains the method encryptButton which gives you the encrypted button pretty easy; if you want to look at the bones then look in the PPCrypto class who offers you the signAndEncrypt method which give you only the encrypted string you need for the field and does show you the process of encrypting the button.

By the way, if you don't know how to get your certificate and your private key (and/or the Paypal's certificate) look here: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_encryptedwebpayments#id08A3I0N30Y4

奢望 2024-10-07 18:16:31

从您的帖子来看,您似乎对加密的含义及其应用范围感到非常困惑。什么是威胁模型? (即如何才能颠覆)。

您不应期望 PayPal 始终处理您发送到客户端浏览器的订单。您必须检查 Paypal 的处理过程。

在订单离开您的网站后,您可以更好地确保订单的完整性,例如,通过将订单的哈希值添加到您发送到 Paypal 的订单号(和盐!)。这应该允许您验证订单,而无需参考 PLU/存储的订单(只要处理从 paypal 返回的脚本知道盐)。

From your post you seem very confused about what encryption means and what to apply it to. What is the threat model? (i.e. how can it be subverted).

There is no way you should expect that paypal will always process the order you sent to the client's browser. You MUST check what Paypal did process.

You can be better assured of the integrity of the order after it leaves your site, e.g. by adding a hash of the order to the order number (and a salt!) you send to Paypal. This should allow you to verify the order without reference to the PLU/stored order (as long as the script processing the return from paypal knows the salt).

乱世争霸 2024-10-07 18:16:31

也许您可以尝试将这些变量放入具有唯一 ID 的临时表中。然后使用该 id 作为按钮。每当客户单击 paypal 按钮时,都会从表中查询变量。我只是希望我能正确理解你的说法 xD

maybe you could try putting those variables in a temporary table with a unique id. then use that id for the buttons. querying the variables from the table whenever the customer clicks the paypal buttons. I just hope i understood your statement right xD

你是年少的欢喜 2024-10-07 18:16:31

执行此操作的唯一方法是每次动态查询 PayPal 以加密按钮。

不过这种方法效率不高,我认为使用PayPal IPN会好得多。网上有很多关于如何做到这一点的示例和课程。

The only way you can do this is by dynamically querying PayPal to encrypt the button each time.

However this method is not efficient, I think it would be much better to use PayPal IPN. There are many examples and classes online on how to do this.

酒解孤独 2024-10-07 18:16:31

我开发了一个 具有 PayPal 网站支付标准的 PHP 集成工具包

您在这里提到的所有问题都是由辅助类在内部处理的。提供了一些基本配置以方便设置。例如,所有加密变量(您的私钥、公共证书...)并受配置影响。文章详细解释了如何使用这些类。

PS:辅助类仅实现 IPN 确认。

I developed a PHP integration toolkit with PayPal Website Payments Standard.

All the issues you mentioned here are handled inside by helper classes. Some basic configuration are provided for easy setup. For example, all encryption variables (your private key, public certificate, ...) and subject to configuration. The article explains in details how to use the classes.

PS: Only IPN confirmation is implemented by the helper classes.

谁与争疯 2024-10-07 18:16:31

知道您的贝宝电子邮件地址的人不会向您发送伪造的发票,询问产品名称和错误的价格吗?如果他们要经历更改您的 js/html 代码以向您发送虚假发票的麻烦...他们可以编写自己的发票(只需提交到“paypal.com/cgi-bin/webscr”的表单)。您真正需要的只是卖家的 PayPal 电子邮件,对吗?

那么为什么要这么麻烦地加密按钮呢?

Couldn't anyone with your paypal email adress send you a bogus invoice, asking for product names at the wrong prices? If they are going to go through the trouble of changing your js/html code to send you a bogus invoice... they could just write their own (just a form submit to 'paypal.com/cgi-bin/webscr'). All you really need is the seller's paypal email right?

So why all the trouble of encrypting buttons?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文