Choosing signature algorithm for PDF signing

Hi!


I use PDF Kit 4.4.0 and Aspose Words 1.0.0 and want to sign PDF documents with a certificate using the following code:

String inputFile = “P:/test.pdf”;
String certificateFile = “P:/cert.p12”;

com.aspose.pdf.kit.PdfFileSignature pFileSignature = new com.aspose.pdf.kit.PdfFileSignature();

// create Signature object
com.aspose.pdf.kit.Signature sgn = new com.aspose.pdf.kit.Signature();

sgn.setRect(new java.awt.Rectangle(100, 100, 100, 100));

pFileSignature.bindPdf(inputFile);

// sign PDF file
pFileSignature.setCertificateFile(certificateFile);
pFileSignature.setMultiSignature(true);
pFileSignature.setSignModel(pFileSignature.SELF);
pFileSignature.setPageNumber(1);
pFileSignature.setPassword(“secret”);
pFileSignature.setSignature(sgn);
pFileSignature.setKeyStoreType(“pkcs12”);

pFileSignature.setCertificationLevel(pFileSignature.NOT_CERTIFIED);
java.io.FileOutputStream outStream = new java.io.FileOutputStream(“P:/out.pdf”);
pFileSignature.save(outStream);


Is it possible to configure the signature algorithm?

When I execute the code then the algorithm “MD5withRSA” is used for signing. I know that Aspose PDF Kit supports the following signature algorithms:
  • <span style=“font-size:10.0pt;
    font-family:“Arial”,“sans-serif”;mso-ansi-language:EN-US;mso-fareast-language:
    EN-US”>MD5withRSA<span style=“font-size:9.0pt;font-family:“Arial”,“sans-serif”;
    mso-ansi-language:EN-US;mso-fareast-language:EN-US”><o:p></o:p>
  • SHA1withRSA
  • SHA256withRSA
  • SHA384withRSA
  • SHA512withRSA

Thank you for your help!

Hi there,

Thanks for your inquiry. I am afraid the required feature is not present in API at the moment. As per my understanding we already passing the certificate file of some specific algorithm then how it would be beneficial to configure signature algorithm again? We will appreciate it if you please share some more details about your requirements so we will investigate it further and update you accordingly.

Moreover please note Aspose.Pdf for Java 4.0.0 was a [autoported version of Aspose.Pdf for .NET](https://blog.aspose.com/2013/04/07/jump-start-about-autoported-aspose.pdf-for-java). In that version we had merged Aspose.Pdf.Kit for java and legacy Aspose.Pdf for Java(aspose.pdf pakcage) into new autoported version. Aspose.Pdf.Kit has been migrated to com.aspose.pdf.facades package. So please also check following documentation link for more details.

Best Regards,

Thank you for your answer!

Sorry, I want to choose the *hash* algorithm which is used to sign the PDF document.

I figured out when using Aspose Words then it works for Word documents:

PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();

PdfDigitalSignatureDetails value =
new PdfDigitalSignatureDetails("P:/cert.p12", "secret",
"test", "test", new Date());
value.setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.SHA_384);

pdfSaveOptions.setDigitalSignatureDetails(value)


But I don't know how to do this for PDF documents with PDF Kit. Do you have any idea?
tobiastobias:
Sorry, I want to choose the *hash* algorithm which is used to sign the PDF document.

I figured out when using Aspose Words then it works for Word documents:

PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();

PdfDigitalSignatureDetails value =
new PdfDigitalSignatureDetails("P:/cert.p12", "secret",
"test", "test", new Date());
value.setHashAlgorithm(PdfDigitalSignatureHashAlgorithm.SHA_384);

pdfSaveOptions.setDigitalSignatureDetails(value)

But I don't know how to do this for PDF documents with PDF Kit. Do you have any idea?
Hi Tobias,

Thanks for sharing the details.

I am afraid the current release of Aspose.Pdf for Java does not support the feature to specify Hash algorithm while signing PDF files. However for the sake of correction, I have logged this requirement as PDFNEWJAVA-34560 in our issue tracking system. We will further look into the details of this requirement and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan