Securing PDFs Using Modern Algorithms
Requirements: Secure PDF
Introduction
Many PDF workflows still rely on legacy algorithms such as RC4 encryption or DSA signatures. These algorithms have modern replacements that are stronger, faster, or both. Secure PDF supports the older algorithms for compatibility with existing documents and certificates, but also supports their modern counterparts for both encryption and signing.
This guide covers how to encrypt PDF documents with AES-256 instead of RC4, and how to sign them with ECDSA or EdDSA instead of RSA or DSA. For the full list of supported algorithms, including all the elliptic curves available for ECDSA, please see this article.
Modern Encryption: AES-256 Over RC4
RC4 is a stream cipher that has been part of the PDF specification since its earliest versions, and Secure PDF still supports this algorithm for opening and updating documents that were encrypted with it. However, RC4 is not recommended for new documents because it has known cryptographic weaknesses.
AES-256 replaces it as the recommended default and is the strongest symmetric option defined by the PDF 2.0 specification (ISO 32000-2). PDFEncrypt uses it by default:
pdfencrypt.InputFile = "input.pdf";
pdfencrypt.OutputFile = "encrypted.pdf";
pdfencrypt.Password = "password";
pdfencrypt.EncryptionAlgorithm = "AES256"; // default
pdfencrypt.Open();
pdfencrypt.Encrypt();
pdfencrypt.Close();
Existing documents encrypted with RC4 or AES-128, for example, can be opened and re-encrypted with AES-256 in the same way without changing anything else about the document.
Modern Signing: ECDSA and EdDSA Over RSA and DSA
While RSA remains a valid and widely used signing algorithm and DSA is still supported for older certificates, elliptic curve alternatives are increasingly becoming the modern choice. ECDSA and EdDSA (using the Ed25519 or Ed448 curve) offer comparable or stronger security with smaller keys and faster signing and verification, and EdDSA in particular is gaining traction for new signing infrastructure.
In PDFSign, the signing algorithm is determined by the private key associated with the signing certificate. Setting SigningCert to a certificate backed by an EC key produces an ECDSA signature, and assigning a certificate backed by an Ed25519 or Ed448 key produces an EdDSA signature, with no additional configuration required.
pdfsign.InputFile = "input.pdf";
pdfsign.OutputFile = "signed.pdf";
pdfsign.SigningCert = new Certificate(CertStoreTypes.cstPFXFile, "eccert.pfx", "password", "*");
pdfsign.SignatureHashAlgorithm = "SHA256"; // default
pdfsign.Open();
pdfsign.Sign();
pdfsign.Close();
The same code signs with RSA, ECDSA, or EdDSA depending only on which certificate is used, which makes it straightforward to migrate existing signing workflows to EC certificates as they become available without touching the surrounding logic.
Putting Both Together
Encryption and signing are independent operations in Secure PDF, and a common workflow is to encrypt a document with AES-256 first, then sign it with ECDSA or EdDSA. The result is a document that is modern on both fronts: strong at rest and backed by a compact, efficient signature.
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.