【问题标题】:How do I digitally sign a PDF in Java using a PEM file?如何使用 PEM 文件在 Java 中对 PDF 进行数字签名?
【发布时间】:2013-07-17 03:37:16
【问题描述】:

我已将我的数字证书导出到 Windows 中受密码保护的 PFX 文件。

我如何用这个对 pdf 进行数字签名?

【问题讨论】:

  • 只有证书是不够的,还需要私钥。还是你都出口了?
  • 包含私钥
  • 是否有额外的边界条件?开源?许可证限制?商业闭源用途?

标签: java pdf digital-signature pem


【解决方案1】:

iTextPdf 是一个很好的 java API,处理 pdf 文件。 还有一个很好的示例文档:http://itextpdf.com/book/digitalsignatures20130304.pdf

还有一个签署PDF文档的例子

【讨论】:

    【解决方案2】:

    我们的SecureBlackbox 可用于使用存储在各种格式文件中的证书、Windows CryptoAPI 和通过 PKCS#11 在硬件设备上的证书签署 PDF 文档。

    【讨论】:

      【解决方案3】:

      我正在使用 Aspose Pdf java sdk 签署 pdf。对于任何库,前两个步骤可能都是相同的。

      如果您还没有证书,请使用 openssl 生成一个 ssl 私钥。显然这会发出警告,因为它没有由 CA 签名。

      openssl req -x509 -newkey rsa:2048 -keyout testkey.pem -out testcert.pem -days 365
      

      接下来将您的密钥转换为 pkcs12 格式的证书。

      openssl pkcs12 -name test -export -in testcert.pem -inkey testkey.pem -out test.pfx
      

      最后使用 Aspose Pdf 或其他库对 pdf 进行签名

              PdfFileSignature pdfSignSingle = new PdfFileSignature();
              //Open the pdf
              pdfSignSingle.bindPdf(pdfFileInputStream);
      
              // Load the certificate using the com.aspose.pdf.PKCS1 object
              PKCS1 pkcs1 = new PKCS1(certificateFileInputStream, certificatePassword);
              pkcs1.setAuthority("Sample Person");
              pkcs1.setReason("I want to sign");
              pkcs1.setContactInfo("some contact info");
              pkcs1.setLocation("here");
              pkcs1.setShowProperties(false);
      
              // Apply the signature. (0,0) is in the lower left corner.
              pdfSignSingle.sign(1, true, new Rectangle(100, 100, 150, 50), pkcs1);
              // Apply the signature image
              pdfSignSingle.setSignatureAppearanceStream(imageFileInputStream);
      
              pdfSignSingle.save(pdfFileOutputStream);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-09
        • 2015-02-13
        • 2012-02-15
        • 1970-01-01
        • 1970-01-01
        • 2015-06-20
        相关资源
        最近更新 更多