Skip to content

Security ​

Foxit PDF SDK for Android provides document encryption and decryption through the Core SDK, including password encryption, certificate encryption, and custom security handlers for different protection levels.

Built-in password prompt in UI Extensions

If you use the full reader (UI Extensions), opening encrypted documents shows a password dialog (PasswordModule) automatically. No extra code is required.

Core Classes ​

ClassDescription
StdSecurityHandlerStandard security handler for password encryption
StdEncryptDataPassword encryption parameters (algorithm, key length, permissions, etc.)
CertificateSecurityHandlerCertificate security handler for certificate encryption

Encryption Type Constants ​

Use PDFDoc.getEncryptionType() to get the current encryption type:

ConstantValueDescription
e_EncryptNone0Not encrypted
e_EncryptPassword1Password encryption
e_EncryptCertificate2Certificate encryption
e_EncryptFoxitDRM3Foxit DRM encryption
e_EncryptCustom4Custom encryption
e_EncryptRMS5Microsoft RMS encryption

Cipher Algorithm Constants ​

ConstantValueDescription
SecurityHandler.e_CipherRC41RC4
SecurityHandler.e_CipherAES2AES

User Permission Constants ​

Set via StdEncryptData user_permissions; combine with bitwise OR:

ConstantValueDescription
PDFDoc.e_PermPrint0x0004Allow printing
PDFDoc.e_PermModify0x0008Allow modifying the document
PDFDoc.e_PermExtract0x0010Allow content extraction
PDFDoc.e_PermAnnotForm0x0020Allow annotations and form filling
PDFDoc.e_PermFillForm0x0100Form filling only
PDFDoc.e_PermExtractAccess0x0200Allow accessibility extraction
PDFDoc.e_PermAssemble0x0400Allow document assembly
PDFDoc.e_PermPrintHigh0x0800Allow high-quality printing

Example: Password Encryption ​

java
import com.foxit.sdk.pdf.PDFDoc;
import com.foxit.sdk.pdf.SecurityHandler;
import com.foxit.sdk.pdf.StdEncryptData;
import com.foxit.sdk.pdf.StdSecurityHandler;

PDFDoc doc = new PDFDoc("path/to/Sample.pdf");
doc.load(null);

// Encrypt metadata, permissions, AES-128
StdEncryptData encryptData = new StdEncryptData(
    true,
    PDFDoc.e_PermModify | PDFDoc.e_PermFillForm | PDFDoc.e_PermPrint,
    SecurityHandler.e_CipherAES,
    16
);

StdSecurityHandler handler = new StdSecurityHandler();
byte[] userPassword = "user123".getBytes();
byte[] ownerPassword = "owner456".getBytes();

if (handler.initialize(encryptData, userPassword, ownerPassword)) {
    doc.setSecurityHandler(handler);
    doc.saveAs("path/to/encrypted.pdf", PDFDoc.e_SaveFlagNormal);
}

Example: Certificate Encryption ​

java
import com.foxit.sdk.pdf.CertificateSecurityHandler;

CertificateSecurityHandler certHandler = new CertificateSecurityHandler();
certHandler.initialize(envelopes, SecurityHandler.e_CipherAES, true);
doc.setSecurityHandler(certHandler);
doc.saveAs("path/to/cert_encrypted.pdf", PDFDoc.e_SaveFlagNormal);

Remove Encryption ​

java
doc.removeSecurity();
doc.saveAs("path/to/decrypted.pdf", PDFDoc.e_SaveFlagNormal);

API Reference

See the API Reference for full StdSecurityHandler, StdEncryptData, and CertificateSecurityHandler documentation.