php - 使用 PHP、Zend 和 openssl 对 PDF 进行数字签名

标签 php zend-framework pdf openssl sign

我正在尝试使用 PHP、openssl 和 Zend 框架(用于 pdf 重新渲染/处理)构建一个简单的 PDF 文档签名例程。

我找到了 this , 但它根本行不通,Zend 无法打开任何 pdf,甚至 Zend 自己的测试 pdf 也无法打开,Zend 也不会报告原因,只是说它“不能”。

我很确定我能够有效地创建 key /证书,因为这已被详细记录,但是是否有可靠的方法将生成的证书附加到 PDF,就像上面的 Zend 扩展曾经建议的那样?

function DigiSignPDF ($pdf_sign_request) {
    if (get_magic_quotes_gpc()) {
        $new_pdf = stripslashes($pdf_sign_request['raw_pdf']);
    } else {
        $new_pdf = $pdf_sign_request['raw_pdf'];
    }
    $test_pdf = stripslashes(file_get_contents('path/Some.pdf'));
    $test_pdf2 = ('path/Some.pdf');
    $pdf = Zend_Pdf::load($new_pdf2);
    //below is the signing code, from another library, it works as long as Zend_Pdf works
    $certificate = file_get_contents('path/certificate.p12');
    $certificatePassword = 'test123';

    if (empty($certificate)) {
        throw new Zend_Pdf_Exception('Cannot retrieve/generate the certificate.');
    }
    $pdf->attachDigitalCertificate($certificate,$certificatePassword);
    $eSig_pdf = $pdf->render();
    file_put_contents('path/signed_pdf.pdf', $eSig_pdf);
}

编辑,添加代码:以上仅在我使用“test_pdf2”作为 Zend_Pdf 的输入时才有效。它可以毫无问题地将证书识别为二进制文件,但我需要能够传递 PDF 而无需将其写入磁盘。

最佳答案

TCPDF支持signing pdf 文件。也许您会在源代码中找到有用的东西。

关于php - 使用 PHP、Zend 和 openssl 对 PDF 进行数字签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10903682/

相关文章:

javascript - 使用 PHP 和 AJAX 插入 mysql 不起作用

iphone - 如何合并带有注释的 PDF 文件

zend-framework - Doctrine 2.0 集成到 Zend Framework 1.10

php - Zendframework/PgSQL fetchAll orderby

php - 使用 PHP 从 MySQL 将 PDF BLOB 加载到 div 或框架中

javascript - 如何在 iOS 上将 iOS Chrome 的 "Open in"功能与 protected 网站后面的 PDF 或大数据 URL 一起使用?

php - Instagram API 如何获取用户 ID?

php - 在弹出窗口中仅显示所有标题的第一个标题信息

javascript - 将 HTML BODY 变量从 PHP 回显到 javascript

php - Zend 框架 : Looking For a Basic "stub" for a project