ARTICLE AD BOX
Creating a digital signature in a PDF on iOS using OpenSSL and QPDF – Unable to generate a valid CMS signature
I am developing an iOS application in Swift that allows users to add a digital signature to a PDF document.
For the implementation, I am trying to build the signing workflow using OpenSSL and QPDF:
OpenSSL – for generating the cryptographic signature and CMS structure
QPDF – for modifying and updating the PDF structure
My goal is to create a valid PDF digital signature that is embedded inside the PDF file and visible as a signed document when opened in PDF viewers.
However, I am currently facing an issue while generating the CMS (Cryptographic Message Syntax) signature structure. Although the code runs without crashing and the PDF file is produced successfully, the digital signature is not actually added to the document. When I open the generated PDF in a viewer, it behaves like a normal unsigned PDF.
What I Have Tried
Used OpenSSL to generate the cryptographic signature
Attempted to construct the CMS signature structure
Used QPDF to modify the PDF and insert the signature placeholder
Verified that the output PDF file is generated without errors
Despite this, the resulting PDF does not contain a valid digital signature.
Background
I have already implemented the same functionality in an Android application, where I was able to successfully add digital signatures to PDFs using a third-party library.
However, for iOS, I have not been able to find a reliable library that supports PDF digital signing in the same way. Because of this, I attempted to build the solution manually using OpenSSL and QPDF, but I am struggling to correctly create and embed the CMS signature structure required by the PDF specification.
My Questions
What is the correct way to generate and embed a CMS digital signature in a PDF using OpenSSL?
Are there any iOS libraries that support PDF digital signing similar to those available on Android?
Is there a recommended approach or framework for implementing PDF digital signatures on iOS?
