我想知道如何在php中籤署文件。我需要簽署一個XML文件。當我執行這段代碼,它給了我下面的錯誤:在PHP中籤名公共x509證書
Warning: openssl_sign(): supplied key param cannot be coerced into a private key in C:\xampp\htdocs\test\index.php on line 35
Warning: openssl_free_key() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test\index.php on line 38
的代碼,這是一個:
$data->save("test.xml");
$signature;
$pkeyid = openssl_pkey_get_public("./public.cer");
$path = 'test.xml';
openssl_sign($path, $signature, $pkeyid);
openssl_free_key($pkeyid);
修正: 好了,我有一個誤解的事實我應該使用公共證書籤署數據,並且我沒有正確加載數據。我改變了它,它工作:) 我使用的功能是這一個:
$ pkeyid = openssl_pkey_get_private(file_get_contents('./ private.key'));
手冊中有一些很好的例子,http://php.net/manual/en/function.openssl-sign.php#example-967 –
你的概念錯了。您*使用私鑰簽名*數據,您*使用公鑰驗證*數據 –