使用 PHP、Zend 和 openssl 对 PDF 进行数字签名 [英] Digitally signing a PDF, using PHP, Zend, and openssl

查看:89
本文介绍了使用 PHP、Zend 和 openssl 对 PDF 进行数字签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to build a simple PDF document signing routine, using PHP, openssl, and the Zend framework (for pdf redering/handling).

我找到了这个,但它根本不起作用,Zend 无法打开任何 pdf,甚至 Zend 自己的测试 pdf 也无法打开,而且 Zend 不会报告原因,只是说它不能".

I've found this, but it simply won't work, Zend is not able to open any pdf's, not even Zend's own test pdf and Zend will not report why, only that it 'cannot'.

我很确定我能够有效地创建密钥/证书,因为这有据可查,但是是否有一种可靠的方法将生成的证书附加到 PDF 中,如上述 Zend 扩展所建议的那样?

I'm pretty sure I would be able to create the keys/certs effectively as that is well documented, but is there a solid approach to attaching the generated certificate to the PDF as the above Zend extension suggests it once did?

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.

Edit, adding code: The above only works if I use 'test_pdf2' as the input for Zend_Pdf. It recognizes the cert as binary with no problems, but I need to be able to pass the PDF without ever writing it to disk.

推荐答案

TCPD 支持 签名 pdf 文件.也许你会在源代码中找到一些有用的东西.

TCPDF supports signing of pdf files. Maybe you find something useful in the source code.

这篇关于使用 PHP、Zend 和 openssl 对 PDF 进行数字签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆