1

I have a PDF document that needs to be both digitally signed and encrypted. I am using ABCPDF and when I apply the digital signature to a document that is encrypted the signature gets invalidated.

The error that is provided by Adobe Acrobat Reader is: "There have been changes made to this document that invalidate the signature"

Source code:

using (Doc doc = new Doc())
{
    doc.Read(pdfPath);
    if (options.Encrypt) 
    {
        doc.Encryption.Type = 4;
        doc.Encryption.SetCryptMethods(CryptMethodType.AESV3);
        doc.Encryption.Password = Encryption.Decrypt(options.UserPassword, PdfSecurityOptions.EncryptionPassword);
        doc.Encryption.OwnerPassword = Encryption.Decrypt(options.OwnerPassword, PdfSecurityOptions.EncryptionPassword);
    }
    if (options.Sign)
    {
        byte[] bytes = Convert.FromBase64String(options.Certificate);
        X509Certificate2 certificate = new X509Certificate2(bytes, Encryption.Decrypt(options.CertificatePassword, PdfSecurityOptions.EncryptionPassword), X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
        PdfUtils.DigitallySign(
            doc,
            options.SignatureText,
            options.Rectangle, 
           certificate
        );
    }  
    doc.Save(savePath);
}

I have tried:

  • Apply the encryption before the signing
  • Apply the encryption after the signing
  • Apply the encryption, save the document and then load and sign it
user1029651
  • 33
  • 1
  • 5

1 Answers1

0

You can't perform a signature after another it's done; doing so, you will corrupt first signature.

To avoid this, you have to use incremental updates, each time a signature is done. Check out Abcpdf Online documentation

http://www.websupergoo.com/helppdfnet/source/6-abcpdf.objects/signature/1-methods/commit.htm


I have tested your code, and the signature appears ok. I think that you have an issue in the way you're adding the field. I see you're using the Abcpdf example code. Maybe you need some changes on it. Can you provide a pdf sample?

Morcilla de Arroz
  • 2,104
  • 22
  • 29
  • The OP only wants to make a single signature (combining it with concurrent encryption which *is* possible in PDFs)... – mkl Nov 09 '17 at 16:04