openssl_pkcs7_sign():获取私钥时出错:尝试对字符串进行签名时出错

时间:2018-11-28 09:56:20

标签: php laravel openssl code-signing

我正在尝试在php laravel项目的控制器中使用以下代码制作签名内容。并用邮递员的方式称呼它。我收到错误消息:openssl_pkcs7_sign(): error getting private key. 我尝试了StackOverflow中的所有答案,但无法解决问题。

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Crypt_RSA;
use DateTime;

class NsdlTest extends Controller
{

    public function __construct(
    )
    {
    }

    public function get_signed_content()
    {

        /* enter data ASPID and TIMESTAMP below */
        $data = '27ABCCN4567K00070128092017121033584111';

        $pemcert = base_path('file_new.pem');
        /* save entered data into parameters.txt file */
        $fp = fopen("/Users/mohammedfaris/source/open-backend-v2/msg.txt", "w");
        fwrite($fp, $data);
        fclose($fp);

        //echo 'file://'.realpath('file_new.pem');

        //echo realpath('file_new.pem');

        /* sign data & generate signature in standard PKCS7 Format */
        $fp1 = fopen("/Users/mohammedfaris/source/open-backend-v2/msg_sig.txt", "w");

        $status = openssl_pkcs7_sign(realpath("/Users/mohammedfaris/source/open-backend-v2/msg.txt"),
            realpath("/Users/mohammedfaris/source/open-backend-v2/msg_sig.txt"),
            $pemcert,
            array ($pemcert, "nsdl@1234"),
            array (),
            0,
            realpath('/Users/mohammedfaris/source/open-backend-v2/file_new.pem'));


        if($status == 1)
        {
            echo "<p>Data signed & signature generated successfully<p>";
        }
        else
        {
            echo "Error: Failed to generate signature";
        }

        fclose($fp1);
        $fr=fopen("/Users/mohammedfaris/source/open-backend-v2/msg_sig.txt", "r");
        $sdata=fread($fr,8192);
        fclose($fr);
        echo $sdata;
    }
}

我正在使用MAC OS。我应该在“状态”部分的“真实路径”中进行任何更改吗?

0 个答案:

没有答案