Decrypt PDFs with AES on Android

PSPDFKit supports fast, in-memory AES-256 decryption using the AesDataProvider class. Unlike other solutions, the PDF is never fully decrypted, and this even works with very large (> 500 MB) documents. The file also will never be written out unencrypted to disk. For information on how to encrypt PDF files so they can be used by the AesDataProvider class, see our Encrypt with AES guide.

How to Decrypt Documents

You can decrypt your PDF in PSPDFKit with the AesDataProvider using the Base64 key you used to encrypt it:

private static final String encryptedPDF = "/sdcard/encrypted.pdf";

// This is the 256-bit AES encryption key stored encoded as Base64. In production apps, this should be secured!
private static final String base64Key = "EQQlw3SNbBwbxkSi1jwwib4B4XqesCVDZv9LftsmE1U=";

AesDataProvider provider = new AesDataProvider(encryptedPDF, base64Key);
const val encryptedPDF = "/sdcard/encrypted.pdf"

// This is the 256-bit AES encryption key stored encoded as Base64. In production apps, this should be secured!
const val base64Key = "EQQlw3SNbBwbxkSi1jwwib4B4XqesCVDZv9LftsmE1U="

val provider = AesDataProvider(encryptedPDF, base64Key)

For more information about this process, please take a look at AesEncryptedFileExample.java in our Catalog example app.