We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Encrypt AND Sign

Hi folks

Using VB.NET with the aspose.pdf dll and have been trying to encrypt a PDF as well as apply a PKCS7 digital signature. Both work independently, but I cannot seem to be able to encrypt AND sign the document. Can anyone provide any assistance?

PS. Currently evaluating the software with a view to purchase and won’t purchase if I can’t get this to work. Only 30 days on trial license so urgent help appreciated.

Thanks,
Scott

Hi Scott,


Thanks for your inquiry. Please note signed document can not be encrypted, it is PDF limitation. If you try to do this by using Adobe Acrobat, the application throws the message - You can not change security on this document because document is signed or certified.

However encrypted document can be singed. You should encrypt a document before signing it.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tial



Thanks for the response. I have tried both method i.e. encrypting then signing and signing then encrypting. Neither work correctly.



I understand now that you cannot sign and then encrypt (this makes sense), but when encrypting and then signing, the signature is no longer valid. When verified via Adobe reader is states that suspicious data is present. Signing alone in the same way results in a signature that is perfectly correct and can be verified.



Any ideas? Maybe you have a code example of how to achieve this successfully?



All the best and thanks again,

Scott

Hi Scott,


Thanks for your feedback. Please check following code snippet, initially we have encrypt the document and later signed. Hopefully it will help you to accomplish the task.


Dim ms As New MemoryStream()

Dim document = New Document(myDir + "HelloWorld.pdf")

document.Encrypt("user", "owner", 0, Aspose.Pdf.CryptoAlgorithm.AESx128)

document.Save(ms)

'create PdfFileSignature object and bind input and output PDF files

Dim pdfSign As New PdfFileSignature()

pdfSign.BindPdf(New Document(ms, "owner"))

'create a rectangle for signature location

Dim rect As New System.Drawing.Rectangle(100, 100, 200, 100)

'set signature appearance

pdfSign.SignatureAppearance = myDir + "Aspose.png"

'create any of the three signature types

'PKCS1 signature = new PKCS1("temp.pfx", "password"); // PKCS#1 or

Dim signature As New PKCS7(myDir + "temp.pfx", "password")

' PKCS#7 or

pdfSign.Sign(1, "Signature Reason", "Contact", "Location", True, rect, _

signature)

'save output PDF file

pdfSign.Save(myDir + "DigitalSign_protected.pdf")

Please feel free to contact us for any further assistance.


Best Regards,

Hi Tilal

Thanks again for all of your help so far.

The code you provided is similar to my own, but I used it anyway to test again. The result is the same. The document is secure and signed, but the signature is no longer valid.

When I check the signature within Adobe Acrobat (on Mac), I get the message, “Error during signature validation. Signature contains incorrect, unrecognised, corrupted, or suspicious data. Support information: Sigdict/ Contents illegal data”

Can you offer any further assistance?

Thanks agin,
Scott

Hi Scott,


Thanks for your feedback. We have tested the scenario over Windows 7 64 bit using Aspose.Pdf for .NET 10.3.0 and it is working fine. However we will test it over MAC and will let you know our findings.

We are sorry for the inconvenience caused.

Best Regards,

Thanks again TIlal.

For clarification, my code is running on Windows Server 2012R2. I’m using VS2012 to code in .NET.

When I try to open the document, I am using a MacBook Pro (Retina, 13-inch, Mid 2014), running OS X Yosemite 10.10.3. The software I am using to view the certificate validity is “Adobe Acrobat Reader DC” version 2015.007.20033.

Good luck with the testing. I will be interested in the results. Meanwhile, I will re-test my code and open on a Windows client with a Windows version of Adobe Acrobat Reader and let you know my findings.

All the best,
Scott

kschambers:
Thanks again TIlal.

For clarification, my code is running on Windows Server 2012R2. I’m using VS2012 to code in .NET.

When I try to open the document, I am using a MacBook Pro (Retina, 13-inch, Mid 2014), running OS X Yosemite 10.10.3. The software I am using to view the certificate validity is “Adobe Acrobat Reader DC” version 2015.007.20033.

Good luck with the testing. I will be interested in the results. Meanwhile, I will re-test my code and open on a Windows client with a Windows version of Adobe Acrobat Reader and let you know my findings.

All the best,
Scott

Hi Scott,

I have further tested the scenario and I am able to reproduce the invalid license issue when using Visual Studio 2010 running over Windows 7(x64) and when viewing the file in Adobe Reader 11.0.2. For the sake of correction, I have logged this problem
as
PDFNEWNET-38697 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.

Thanks for the update Nayer. Just out of interest however, what version of Visual Studio have you guys been using when the code was working okay? I may be able to upgrade my version.

Thanks,
Scott

Hi Scott,


Thanks for your feedback. I have tested the scenario over Win 7 64 bit using VS2010. Moreover, Adobe Acrobat Pro XI validating the signature in resultant PDF file. Whereas Adobe Acrobat Reader 11.0.10 identifies UNKNOWN signature validity. Please find screenshots for reference.

Best Regards,

Hi Tital, Nayyer


We have the exact same problem using Aspose.Pdf for .NET 10.5.0.

Signature verification works with Acrobat Reader DC (ver.: 2015.007.20033). In Acrobat Reader XI (version: 11.0.10) and older we get signature invalid message (see the image attached).

Is there anything new on this issue?

Thanks.

Regards,
Uros

Hi Uros,


Thanks for your inquiry. I am afraid the reported issue is still not resolved. We will notify you as soon as we made some significant progress towards issue resolution.

We are sorry for the inconvenience caused.

Best Regards,

uros.goljat:
We have the exact same problem using Aspose.Pdf for .NET 10.5.0.

Signature verification works with Acrobat Reader DC (ver.: 2015.007.20033). In Acrobat Reader XI (version: 11.0.10) and older we get signature invalid message (see the image attached).

Is there anything new on this issue?
Hi Uros,

Adding more to Tilal’s comments, can you please share your source PDF file and signature file so that we can explicitly test the scenario in our environment. Please note that each document has separate structure and complexity, so we need to explicitly test the scenario and need to figure out the reasons causing issue in your scenario. We are sorry for your inconvenience.
Hi Scott,

codewarior:
I have further tested the scenario and I am able to reproduce the invalid license issue when using Visual Studio 2010 running over Windows 7(x64) and when viewing the file in Adobe Reader 11.0.2. For the sake of correction, I have logged this problem as PDFNEWNET-38697 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Thanks for your patience. In reference to PDFNEWNET-38697, please note you can not encrypt document because document already signed and certified. It can be double checked with Adobe software, try to encrypt the document and later to sign - the signing features are disabled. And otherwise, signing and then encrypting are not provided too.

Please feel free to contact us for any further assistance.

Best Regards,

A post was split to a new topic: Encrypting and Signing document corrupts signature in PDF