I am working with adding digital signature in pdf using JAVA. I have gone through so many APIs for it. But I couldn't get any example for adding the existing pfx file directly into the pdf.
I have tried with Apache PdfBox :
PDSignature signature = null;
File file = new File("path\\REPORT.pdf");
PDDocument doc=PDDocument.load(file);
FileInputStream pkcs12Stream = new FileInputStream ("path\\abc.pfx");
KeyStore store = KeyStore.getInstance("PKCS12");
store.load(pkcs12Stream, "pwd@123".toCharArray());
PDSignature sign=new PDSignature();
byte[] bytes = IOUtils.toByteArray(pkcs12Stream);
sign.setContents(bytes);
doc.addSignature(sign); // to add the signature in the pfx file.
FileOutputStream fos = new FileOutputStream("path\\REPORT_signed.pdf");
doc.saveIncremental(fos);
pkcs12Stream.close();
Now here I do not get any exception, But it's generating the currapted signed file which will not load because of the below statment.
doc.addSignature(sign);
Because it's not able to convert in bytes, this is my assumption.
Is there any way that I can use existing pfx file and generate the signed pdf file.
Please suggest me on this.