使用PHP和laravel的数字签名PDF文件 [英] Digital Sign PDF File with PHP and laravel
问题描述
您好,我在提出此问题之前进行了很多搜索.我知道有一个有效的方法来签名pdf setasign.com
Hello i search a lot before make this question. I know there is a paied option to sign pdf setasign.com
我尝试使用php函数:
I try to use php function:
openssl_pkcs7_sign( FULL_PATH . "/pdforiginal.pdf", //ORIGIANL PDF
FULL_PATH ."signedPDF.pdf", // SIGNED PDF
"file://" . FULL_PATH . "signing_cert.pem",
array( "file://" . FULL_PATH. "private_key.pem",""),array());
signing_cert.pem<-////我不明白这是什么,我只拥有private_key和public_key.我在这里看到了一些人们使用private_key的示例.
signing_cert.pem <- // I Dont understand what is this i just have private_key and public_key. I see some examples where people use private_key here.
我的私钥没有密码,我应该使用空白的"或null?
My private key dont have password shoud i use blank "" or null ?
如果任何人都不能给我一些有关该主题的信息,那将非常有帮助.
If anyone can give me little information about this topic would be really helpful.
推荐答案
我找到了解决方案.我使用FPDI库打开pdf,并使用tcpdf库对其进行签名.这使过程非常简单.
I find the solution. I use FPDI library to open pdf and use tcpdf library to sign it. That makes the process really simple.
require_once('tcpdf_include.php');
require_once "fpdi.php";
$pdf = new FPDI('P', 'mm', 'A4'); //FPDI extends TCPDF
$pages = $pdf->setSourceFile('document.pdf');
/*
NOTES:
- To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
- To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
- To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
*/
$certificate = 'file://data/cert/tcpdf.crt';
// set additional information
$info = array(
'Name' => 'TCPDF',
'Location' => 'Office',
'Reason' => 'Testing TCPDF',
'ContactInfo' => 'http://www.tcpdf.org',
);
for ($i = 1; $i <= $pages; $i++)
{
$pdf->AddPage();
$page = $pdf->importPage($i);
$pdf->useTemplate($page, 0, 0);
// set document signature
$pdf->setSignature($certificate, $certificate, 'tcpdfdemo', '', 2, $info);
}
这篇关于使用PHP和laravel的数字签名PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!