Security
Foxit PDF SDK for iOS provides document encryption and decryption via Core SDK, including password encryption, certificate encryption, and custom security handlers.
UI Extensions password prompt
With the full reader (UI Extensions), encrypted documents show a password dialog automatically—no extra code required.
Core classes
| Class | Description |
|---|---|
FSStdSecurityHandler | Standard security handler for password encryption |
FSStdEncryptData | Password encryption parameters (cipher, key length, permissions) |
FSCertificateSecurityHandler | Certificate-based encryption |
Encryption type constants
Use [FSPDFDoc getEncryptionType]:
| Constant | Description |
|---|---|
FSPDFDocEncryptNone | Not encrypted |
FSPDFDocEncryptPassword | Password |
FSPDFDocEncryptCertificate | Certificate |
FSPDFDocEncryptFoxitDRM | Foxit DRM |
FSPDFDocEncryptCustom | Custom |
FSPDFDocEncryptRMS | Microsoft RMS |
User permission constants
Set via user_permissions on FSStdEncryptData (bitwise OR):
| Constant | Description |
|---|---|
FSPDFDocPermPrint | |
FSPDFDocPermModify | Modify document |
FSPDFDocPermExtract | Extract content |
FSPDFDocPermAnnotForm | Add annotations and fill forms |
FSPDFDocPermFillForm | Fill forms only |
FSPDFDocPermExtractAccess | Accessibility extraction |
FSPDFDocPermAssemble | Assemble document |
FSPDFDocPermPrintHigh | High-quality print |
Example: password encryption
objc
#import <FoxitRDK/FSPDFObjC.h>
FSPDFDoc *doc = [[FSPDFDoc alloc] initWithPath:@"path/to/Sample.pdf"];
[doc load:nil];
// Encryption parameters
FSStdEncryptData *encryptData = [[FSStdEncryptData alloc] init];
[encryptData setIs_encrypt_metadata:YES];
[encryptData setUser_permissions:FSPDFDocPermModify |
FSPDFDocPermFillForm |
FSPDFDocPermPrint];
[encryptData setCipher:FSSecurityHandlerCipherAES];
[encryptData setKey_length:16];
FSStdSecurityHandler *handler = [[FSStdSecurityHandler alloc] init];
NSData *userPwd = [@"user123" dataUsingEncoding:NSUTF8StringEncoding];
NSData *ownerPwd = [@"owner456" dataUsingEncoding:NSUTF8StringEncoding];
if ([handler initialize:encryptData userPassword:userPwd ownerPassword:ownerPwd]) {
[doc setSecurityHandler:handler];
[doc saveAs:@"path/to/encrypted.pdf" saveFlags:FSPDFDocSaveFlagNormal];
}Remove encryption
objc
[doc removeSecurity];
[doc saveAs:@"path/to/decrypted.pdf" saveFlags:FSPDFDocSaveFlagNormal];API reference
See the API reference for FSStdSecurityHandler, FSStdEncryptData, and FSCertificateSecurityHandler.