简体   繁体   中英

Sign PDF Document using certificate and private key with iText 5

I have a certificate which is used for tls/SSL in my web server. The certificate was issued by a trusted authority and I am having the RSA private key and x509 certificate for the same. The key usage of the certificate says that it can be used for digital signature. Now i need to digitally sign PDF using that certificate, but in all examples, they are asking for a pkcs12 file which I don't have. Is there is any solution that i can sign the pdf using that key and cer or i can generate the pkcs12 using any openssl command?

It is strange that a certificate can be used for TLS and for digital signature. Usually the key usage is different and the common name matches the domain name.

If that is your requirement you can build a pkcs12 with openssl from key and x509 certificate

 openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

You can also sign the PDF using directly key and certificate (it is not mandatory to include them into a .p12 file). See some itext digital signature examples hre

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM