2013-07-18 66 views
0

我已经将我的数字证书导出到Windows中受密码保护的PFX文件中。如何使用PEM文件对Java进行PDF数字签名?

如何用此数字签名PDF?

+1

仅仅证书是不够的,还需要私有密钥。或者你有两个出口? – mkl

+0

包含私钥 –

+0

是否还有其他边界条件?开源?许可限制?商业闭源使用? – mkl

回答

0

一个例子我们SecureBlackbox可以用来登录的Windows CryptoAPI的使用存储在文件中以各种格式的证书,PDF文档并通过PKCS#11在硬件设备上。

3

我正在用Aspose Pdf java sdk签署pdfs。对于任何图书馆来说,前两个步骤可能都是相同的。

如果您还没有证书,请使用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); 
相关问题