PDF.co can decrypt a file before processing it, encrypt the file it produces, or do both in one request. For example, you can convert an encrypted PDF to JPG, or merge two encrypted PDFs and save the result with a different key.
Set these options in profiles. For a direct API request, send the profile as a JSON string inside the request body, as shown below. If an integration gives you a separate Profiles text field, paste the profile JSON there without the surrounding string quotes or escape characters.
PDF.co supports AES128, AES192, and AES256. The examples below use AES128 with a 16-character ASCII key and a 16-character ASCII initialization vector (IV). The keys and IVs shown are public test values. For your own files, use a securely generated secret key and a fresh IV for each encryption. Keep the key and IV so you can decrypt the output later. PDF.co redacts these settings from API logs.
Encrypt an output file
Use DataEncryptionAlgorithm, DataEncryptionKey, and DataEncryptionIV. This request converts a regular PDF to JPG and encrypts the output.
POST https://api.pdf.co/v1/pdf/convert/to/jpg
{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-to-image/sample.pdf",
"profiles": "{\"DataEncryptionAlgorithm\":\"AES128\",\"DataEncryptionKey\":\"ExampleOutputKey\",\"DataEncryptionIV\":\"DemoOutputVector\"}"
}Decrypt an input file
Use DataDecryptionAlgorithm, DataDecryptionKey, and DataDecryptionIV. All three values must match those used to encrypt the input. The following profile matches PDF.co’s public encrypted sample.
{
"DataDecryptionAlgorithm": "AES128",
"DataDecryptionKey": "HelloThisKey1234",
"DataDecryptionIV": "TreloThisKey1234"
}To convert that sample to JPG, send this request body to POST https://api.pdf.co/v1/pdf/convert/to/jpg.
{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/encryption/sample_encrypted_aes128.pdf",
"profiles": "{\"DataDecryptionAlgorithm\":\"AES128\",\"DataDecryptionKey\":\"HelloThisKey1234\",\"DataDecryptionIV\":\"TreloThisKey1234\"}"
}Decrypt the inputs and encrypt the merged PDF
This example merges two copies of the encrypted sample. Put both URLs in a single comma-separated url string. The DataDecryption settings open the inputs. The DataEncryption settings apply a separate key and IV to the merged PDF.
POST https://api.pdf.co/v1/pdf/merge
{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/encryption/sample_encrypted_aes128.pdf,https://pdfco-test-files.s3.us-west-2.amazonaws.com/encryption/sample_encrypted_aes128.pdf",
"profiles": "{\"DataDecryptionAlgorithm\":\"AES128\",\"DataDecryptionKey\":\"HelloThisKey1234\",\"DataDecryptionIV\":\"TreloThisKey1234\",\"DataEncryptionAlgorithm\":\"AES128\",\"DataEncryptionKey\":\"ExampleOutputKey\",\"DataEncryptionIV\":\"DemoOutputVector\"}"
}To read the merged PDF in a later PDF.co request, use the returned file URL. Set the decryption algorithm, key, and IV to the values used to encrypt the output. For this example, pass the following profile to POST https://api.pdf.co/v1/pdf/info to read the page count. The merged sample has two pages.
{
"DataDecryptionAlgorithm": "AES128",
"DataDecryptionKey": "ExampleOutputKey",
"DataDecryptionIV": "DemoOutputVector"
}