目前我发现有关数据结构的是一个Paypal示例代码,它演示了加密按钮在您的网站上的显示方式(可在此处找到:https://www.paypal.com/cgi-bin/webscr?cmd=p/xcl/rec/ewp-techview-outside

乍一看,我的结果似乎完全如Paypal eaxmple链接所示,除了当我继续单击按钮时,我收到Paypal错误,说“我们无法解密证书ID” . 因此,我认为问题是数据结构如何或实际加密本身(我还做了很多调试,并确保所有证书和密钥都成功注册) . 下面的代码演示了我的php代码创建的按钮 .

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
  <input type="hidden" name="cmd" value="_s-xclick">
  <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">
  <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIH6QYJKM585oH7A[to much data to show]9QRQIpFZzRK6cJu6QQO+q/xfiw==-----END PKCS7-----">
</form>

这是我加密前的数据:

cert_id=9CE6NSORUBVMC cmd=_xclick business=sales@mycompany.com item_name=Cat Litter #40 amount=12.95 no_shipping=1 return=http://test183653.comli.com/MainPage.php cancel_return=http://test183653.comli.com/MainPage.php no_note=1 currency_code=USD bn=PP-BuyNowBF

我目前正在使用上面的格式作为在互联网上拼凑点信息的结果,但它似乎不起作用(当我删除字符串中的所有空格时也不起作用) . 从而,

MAIN QUESTION: 任何人都可以告诉我或指出我正确的方向在加密之前学习正确的数据格式吗?

对于有兴趣检查是否是通过不正确加密创建错误的代码的任何人,可以在下面找到加密数据的函数:

function encryptButton($parameters) {

    if (($this->certificateID == '') ||
    !IsSet($this->certificate) ||
    !IsSet($this->paypalCertificate)) {
      return FALSE;
    }

    $clearText = '';
    $encryptedText = '';

    $clearText = 'cert_id='.$this->certificateID;

    foreach (array_keys($parameters) as $key) {

      $clearText .= "\n{$key}={$parameters[$key]}";
    }

    $clearFile = tempnam($this->tempFileDirectory, 'cle');
    $signedFile = preg_replace('/cle/', 'signed', $clearFile);
    $encryptedFile = preg_replace('/cle/', 'encrypted', $clearFile);

    $out = fopen($clearFile, 'wb');
    fwrite($out, $clearText); 
    fclose($out);

    //openssl_pkcs7_sign occurs here
    if (!openssl_pkcs7_sign($clearFile, $signedFile, $this->certificate, $this->privateKey, array(), PKCS7_BINARY)) {
      return FALSE;
    }

    $signedData = explode("\n\n", file_get_contents($signedFile));

    $out = fopen($signedFile, 'wb');
    fwrite($out, base64_decode($signedData[1]));
    fclose($out);

    //openssl_pkcs7_encrypt occurs here
    if (!openssl_pkcs7_encrypt($signedFile, $encryptedFile, $this->paypalCertificate, array(), PKCS7_BINARY)) {
      return FALSE;
    }

    $encryptedData = explode("\n\n", file_get_contents($encryptedFile));

    $encryptedText = $encryptedData[1];

    @unlink($clearFile);
    @unlink($signedFile);
    @unlink($encryptedFile);

    return $encryptedText;

  }


  function getEncryptedString($params) {
  return "-----BEGIN PKCS7-----".str_replace("\n", "", $this->encryptButton($params))."-----END PKCS7-----"; }

}