如何在 OpenSSL 中制作证书以与 php 一起使用?

发布于 2024-10-10 03:29:49 字数 407 浏览 9 评论 0原文

最近,我决定为我的 php 商店添加 Banklink 付款选项,在阅读实施规范后,一切似乎都正常,但有一点。所有公钥(证书)交换均采用X509格式。现在,最后一个是什么意思?它与常规密码保护的 .pem 文件有何不同? 另外,对于常规密码保护的 .pem 文件,我无法使用由 openssl_sign() 函数签名的 openssl_verify() 等 php 函数。

我可以在这里得到一些建议吗,因为提供这种付款方式的银行对此的信息很少,而且我对此完全陌生。

所以我在这里需要做的例程是为他们生成 request.pem 并将其发送给他们。之后他们会签署它或我不知道的任何东西,我应该能够在我的应用程序中使用它。

请告诉我我的信息是否不够,因为正如我所说,我对证书或 openssl 知之甚少。

Recently i decided to add banklink payment option for my php store and after reading specifications of implementation everything seems okey, but the 1 point of it. All public key(certificates) exchange are in X509 format. Now what does that last one mean and how it's different from regular password protected .pem file?
Also with regular password protected .pem file i cannot use php function like openssl_verify() signed by openssl_sign() function.

Could i get some advice here please since the bank that offering this payment method has very little information on this and im totally newb to this.

So the routine i need to do here is generate request.pem for them and send it to them. After that they will sign it or whatever i dunno and i should be able to use it in my application.

Please, tell me if my information is not enough because as i told i don't know much when in comes to certificates or openssl.

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

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

发布评论

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

评论(4

月牙弯弯 2024-10-17 03:29:49

PEM 文件包含加密和 Base64 编码的“原始”证书/私钥值,因此使用 PEM 的函数也应该使用原始证书。 OpenSSL 应该能够从一种格式转换为另一种格式。

PEM file contains encrypted and base64-encoded 'raw' certificate/private key value, so functions that work with PEM should also work with raw certificates. OpenSSL should be able to convert from one format to another.

撕心裂肺的伤痛 2024-10-17 03:29:49

您必须使用 curl 概念。

curl_setopt($ch, CURLOPT_SSLCERT,'CA.pem');

You have to use curl concept.

curl_setopt($ch, CURLOPT_SSLCERT,'CA.pem');
讽刺将军 2024-10-17 03:29:49

老实说,PHP 中的 OpenSSL 功能很糟糕。你最好的选择是选择一个很棒的包,比如 phpseclib

Honestly, the OpenSSL capabilities in PHP are abysmal. Your best bet is to go for an awesome package like phpseclib.

是伱的 2024-10-17 03:29:49

很久以前我也在做类似的事情。不同的是他们只是给了我 pem 文件,我用它来连接到他们的服务器。

下面我为大家写下我的猜测。 :)

  1. 使用 openssl 工具生成 myreq.pem。
  2. 将 myreq.pem 发送给他们并获取签名证书 ca.pem。
  3. 在 PHP 中使用 ca.pem,如下所示。

 

$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'verify_peer', false); //or can be true
stream_context_set_option($context, 'ssl', 'cafile', "ca.pem");
stream_context_set_option($context, 'ssl', 'local_cert', "ca.pem");
stream_context_set_option($context, 'ssl', 'passphrase', 'your pem file password');
//instead tls can be ssl, sslv3, sslv2 depending requirements, 10 is timeout
$sock = stream_socket_client("tls://host:port", $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context); 
fwrite($sock, "Hi server\r\n");
$strResponse;
while(!feof($sock)) { $strResponse = $strResponse . fgets($sock, 1024); }
fclose($s);
echo $strResponse;

long time ago i was doing something similar. The difference is they just gave me the pem file, and i used it to connect to their server.

Below I wrote my guiessing for you. :)

  1. Generate myreq.pem using openssl tool.
  2. Send myreq.pem to them and get signed certificate ca.pem.
  3. Use ca.pem in PHP like below.

 

$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'verify_peer', false); //or can be true
stream_context_set_option($context, 'ssl', 'cafile', "ca.pem");
stream_context_set_option($context, 'ssl', 'local_cert', "ca.pem");
stream_context_set_option($context, 'ssl', 'passphrase', 'your pem file password');
//instead tls can be ssl, sslv3, sslv2 depending requirements, 10 is timeout
$sock = stream_socket_client("tls://host:port", $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context); 
fwrite($sock, "Hi server\r\n");
$strResponse;
while(!feof($sock)) { $strResponse = $strResponse . fgets($sock, 1024); }
fclose($s);
echo $strResponse;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文