Php Curl错误:无法设置私钥文件:';test.pem';型质子交换膜

Php Curl错误:无法设置私钥文件:';test.pem';型质子交换膜,php,ssl,curl,Php,Ssl,Curl,我的Pem文件是这种格式的 Bag Attributes localKeyID: friendlyName: test subject=/C=GB/ST=London/L=Soho/O=Rightmove/OU=RTDF/CN=cmexpertise issuer=/C=GB/ST=London/L=Soho/O=Rightmove/OU=Operations/CN=RTDF Test Issuing CA v3/emailAddress=operations@rightmove.co.uk -

我的Pem文件是这种格式的

Bag Attributes
localKeyID:
friendlyName: test
subject=/C=GB/ST=London/L=Soho/O=Rightmove/OU=RTDF/CN=cmexpertise
issuer=/C=GB/ST=London/L=Soho/O=Rightmove/OU=Operations/CN=RTDF Test Issuing CA v3/emailAddress=operations@rightmove.co.uk
-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----

Bag Attributes
localKeyID:
friendlyName: test
subject=/C=GB/ST=London/L=Soho/O=Rightmove/OU=RTDF/CN=cmexpertise
issuer=/C=GB/ST=London/L=Soho/O=Rightmove/OU=Operations/CN=RTDF Test Issuing CA v3/emailAddress=operations@rightmove.co.uk
-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----

Bag Attributes
localKeyID:
friendlyName: test
subject=/C=GB/ST=London/L=Soho/O=Rightmove/OU=RTDF/CN=cmexpertise
issuer=/C=GB/ST=London/L=Soho/O=Rightmove/OU=Operations/CN=RTDF Test Issuing CA v3/emailAddress=operations@rightmove.co.uk
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,B9E036426B7AEDA6
-----END RSA PRIVATE KEY-----
我正在使用PHP的这段代码。我得到了这个错误

Curl错误:无法设置私钥文件:“test.pem”类型pem

代码

$json\u data//这是一个json数组。
$url=”https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
//$pemFile=tmpfile();
//fwrite($pemFile,“test.pem”)//pem文件的路径
//$tempPemPath=stream\u get\u meta\u数据($pemFile);
//$tempPemPath=$tempPemPath['uri'];
curl_setopt($ch,CURLOPT_SSLCERT,“test.pem”);
curl_setopt($ch,CURLOPT_SSLCERTTYPE,“PEM”);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type:application/javascript'));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,True);
curl_setopt($ch,CURLOPT_POST,True);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS,$json_data);
curl_setopt($ch,CURLOPT_VERBOSE,true);
$result=curl\u exec($ch);
如果(!$result)
{
echo“Curl Error:.Curl_Error($ch);
}
其他的
{
回声“成功:.”结果;
}
$info=curl\u getinfo($ch);
卷曲关闭($ch);//闭合卷曲处理器
if(空($info['http_code'])){
die(“没有返回HTTP代码”);
}否则{
//加载HTTP代码
$http_code=parse_ini_文件(“path/to/the/ini/file/I/pasted/over”);
//回声结果
回显“服务器响应:
”; echo$info['http_code']。“.$http_code[$info['http_code']”; }
我在线检查证书解码器: 证书在此网站上有效

所以这里的问题是什么,我想不出来。 我也尝试使用ssl命令。

有两个错误

  • pem文件的一个错误生成pem文件时出错
  • 另一个错误是我没有在代码中包含CURLOPT_SSLCERTPASSWD()
代码


Curl错误:无法加载PEM客户端证书,OpenSSL错误:0200107B:系统库:fopen:未知错误,(未找到密钥、错误的密码短语或错误的文件格式?)。这是我在使用php代码和PEM文件时遇到的错误。原因是该文件中的私钥与证书中相应的公钥不匹配。@Reddy。谢谢你的回复,兄弟。有两个错误,一个是pem文件的错误,一个是pem文件的错误,另一个是我没有在代码中包含CURLOPT_SSLCERTPASSWD()。
   $json_data  // it's a json array.

    $url = "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);

    // $pemFile = tmpfile();
    // fwrite($pemFile, "test.pem");   //the path for the pem file
    // $tempPemPath = stream_get_meta_data($pemFile);
    // $tempPemPath = $tempPemPath['uri'];

    curl_setopt($ch, CURLOPT_SSLCERT, "test.pem"); 
    curl_setopt($ch,CURLOPT_SSLCERTTYPE,"PEM");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/javascript'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
    curl_setopt($ch, CURLOPT_POST, True);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
    curl_setopt($ch, CURLOPT_VERBOSE, true);

    $result = curl_exec($ch);

    if(!$result)
    {
        echo "Curl Error: " . curl_error($ch);
    }
    else
    {
        echo "Success: ". $result;
    }

    $info = curl_getinfo($ch);

    curl_close($ch); // close cURL handler

    if (empty($info['http_code'])) {
            die("No HTTP code was returned"); 
    } else {
        // load the HTTP codes
        $http_codes = parse_ini_file("path/to/the/ini/file/I/pasted/above");

        // echo results
        echo "The server responded: <br />";
        echo $info['http_code'] . " " . $http_codes[$info['http_code']];
    }
    curl_setopt($ch,CURLOPT_SSLCERTTYPE,"PEM");
    curl_setopt($ch, CURLOPT_SSLCERT, "test.pem");  
    curl_setopt($ch, CURLOPT_SSLCERTPASSWD, '******'); // password