|
@@ -49,7 +49,7 @@
|
|
|
|
|
|
#pragma mark - Samples Methods
|
|
|
|
|
|
-- (void)encryptByUserPassword:(CPDFDocument *)document {
|
|
|
+- (void)encryptByUserPassword:(CPDFDocument *)oldDocument {
|
|
|
{
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 1: Document use RC4 encrypt done\n"];
|
|
@@ -64,10 +64,10 @@
|
|
|
|
|
|
// Save the document in the test PDF file
|
|
|
NSURL *encryptUserRC4URL = [NSURL fileURLWithPath:writeFilePath];
|
|
|
- [document writeToURL:encryptUserRC4URL];
|
|
|
+ [oldDocument writeToURL:encryptUserRC4URL];
|
|
|
|
|
|
// Create a new document for test PDF file
|
|
|
- document = [[CPDFDocument alloc] initWithURL:encryptUserRC4URL];
|
|
|
+ CPDFDocument *document = [[CPDFDocument alloc] initWithURL:encryptUserRC4URL];
|
|
|
[self.userPasswordURLs addObject:encryptUserRC4URL];
|
|
|
|
|
|
// Set encryption attributes
|
|
@@ -93,10 +93,10 @@
|
|
|
|
|
|
// Save the document in the test PDF file
|
|
|
NSURL *encryptUserAES128URL = [NSURL fileURLWithPath:writeFilePath];
|
|
|
- [document writeToURL:encryptUserAES128URL];
|
|
|
+ [oldDocument writeToURL:encryptUserAES128URL];
|
|
|
|
|
|
// Create a new document for test PDF file
|
|
|
- document = [[CPDFDocument alloc] initWithURL:encryptUserAES128URL];
|
|
|
+ CPDFDocument *document = [[CPDFDocument alloc] initWithURL:encryptUserAES128URL];
|
|
|
[self.userPasswordURLs addObject:encryptUserAES128URL];
|
|
|
|
|
|
// Set encryption attributes
|
|
@@ -122,10 +122,10 @@
|
|
|
|
|
|
// Save the document in the test PDF file
|
|
|
NSURL *encryptUserAES256URL = [NSURL fileURLWithPath:writeFilePath];
|
|
|
- [document writeToURL:encryptUserAES256URL];
|
|
|
+ [oldDocument writeToURL:encryptUserAES256URL];
|
|
|
|
|
|
// Create a new document for test PDF file
|
|
|
- document = [[CPDFDocument alloc] initWithURL:encryptUserAES256URL];
|
|
|
+ CPDFDocument *document = [[CPDFDocument alloc] initWithURL:encryptUserAES256URL];
|
|
|
[self.userPasswordURLs addObject:encryptUserAES256URL];
|
|
|
|
|
|
// Set encryption attributes
|
|
@@ -151,10 +151,10 @@
|
|
|
|
|
|
// Save the document in the test PDF file
|
|
|
NSURL *encryptUserNoEncryptAlgoURL = [NSURL fileURLWithPath:writeFilePath];
|
|
|
- [document writeToURL:encryptUserNoEncryptAlgoURL];
|
|
|
+ [oldDocument writeToURL:encryptUserNoEncryptAlgoURL];
|
|
|
|
|
|
// Create a new document for test PDF file
|
|
|
- document = [[CPDFDocument alloc] initWithURL:encryptUserNoEncryptAlgoURL];
|
|
|
+ CPDFDocument *document = [[CPDFDocument alloc] initWithURL:encryptUserNoEncryptAlgoURL];
|
|
|
[self.userPasswordURLs addObject:encryptUserNoEncryptAlgoURL];
|
|
|
|
|
|
// Set encryption attributes
|
|
@@ -167,7 +167,7 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-- (void)encryptByOwnerPassword:(CPDFDocument *)document {
|
|
|
+- (void)encryptByOwnerPassword:(CPDFDocument *)oldDocument {
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 5: Encrypt by owner password done\n"];
|
|
|
|
|
@@ -181,10 +181,10 @@
|
|
|
|
|
|
// Save the document in the test PDF file
|
|
|
NSURL *encryptOwnerRC4URL = [NSURL fileURLWithPath:writeFilePath];
|
|
|
- [document writeToURL:encryptOwnerRC4URL];
|
|
|
+ [oldDocument writeToURL:encryptOwnerRC4URL];
|
|
|
|
|
|
// Create a new document for test PDF file
|
|
|
- document = [[CPDFDocument alloc] initWithURL:encryptOwnerRC4URL];
|
|
|
+ CPDFDocument *document = [[CPDFDocument alloc] initWithURL:encryptOwnerRC4URL];
|
|
|
[self.userPasswordURLs addObject:encryptOwnerRC4URL];
|
|
|
|
|
|
// Set encryption attributes
|
|
@@ -199,7 +199,7 @@
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in EncryptOwnerRC4Test.pdf\n\n"];
|
|
|
}
|
|
|
|
|
|
-- (void)encryptByAllPasswords:(CPDFDocument *)document {
|
|
|
+- (void)encryptByAllPasswords:(CPDFDocument *)oldDocument {
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 6: Encrypt by Both user and owner passwords done\n"];
|
|
|
|
|
@@ -213,10 +213,10 @@
|
|
|
|
|
|
// Save the document in the test PDF file
|
|
|
NSURL *encryptAllAES256URL = [NSURL fileURLWithPath:writeFilePath];
|
|
|
- [document writeToURL:encryptAllAES256URL];
|
|
|
+ [oldDocument writeToURL:encryptAllAES256URL];
|
|
|
|
|
|
// Create a new document for test PDF file
|
|
|
- document = [[CPDFDocument alloc] initWithURL:encryptAllAES256URL];
|
|
|
+ CPDFDocument *document = [[CPDFDocument alloc] initWithURL:encryptAllAES256URL];
|
|
|
[self.userPasswordURLs addObject:encryptAllAES256URL];
|
|
|
|
|
|
// Set encryption attributes
|
|
@@ -237,11 +237,11 @@
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Done. Results saved in EncryptAllAES256Test.pdf\n\n"];
|
|
|
}
|
|
|
|
|
|
-- (void)unlock:(CPDFDocument *)document {
|
|
|
+- (void)unlock {
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 7: Unlock with owner password and user password\n"];
|
|
|
|
|
|
- // Save a document in Sandbox
|
|
|
+ // Get Sandbox path for saving the PDF File
|
|
|
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
|
|
|
NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Encrypt"];
|
|
|
NSString *documentFolder = [[NSBundle mainBundle] pathForResource:@"AllPasswords" ofType:@"pdf"];
|
|
@@ -254,8 +254,10 @@
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
|
|
|
[[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
|
|
|
|
|
|
+ // Unlock the document and print document permission information
|
|
|
+ // It is worth noting that the document is only unlocked, not decrypted, and the password is still required for the next opening
|
|
|
NSURL *unlockAllPasswordsURL = [NSURL fileURLWithPath:writeFilePath];
|
|
|
- document = [[CPDFDocument alloc] initWithURL:unlockAllPasswordsURL];
|
|
|
+ CPDFDocument *document = [[CPDFDocument alloc] initWithURL:unlockAllPasswordsURL];
|
|
|
|
|
|
[document unlockWithPassword:@"Owner"];
|
|
|
|
|
@@ -268,11 +270,11 @@
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingFormat:@"AllowsFormFieldEntry:%@\n\n", document.allowsFormFieldEntry ? @"YES" : @"NO"];
|
|
|
}
|
|
|
|
|
|
-- (void)decrypt:(CPDFDocument *)document {
|
|
|
+- (void)decrypt {
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"Samples 8: Decrypt with owner password and user password\n"];
|
|
|
|
|
|
- // Save a document in Sandbox
|
|
|
+ // Get Sandbox path for saving the PDF File
|
|
|
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
|
|
|
NSString *writeDirectoryPath = [NSString stringWithFormat:@"%@/%@", path, @"Encrypt"];
|
|
|
NSString *documentFolder = [[NSBundle mainBundle] pathForResource:@"AllPasswords" ofType:@"pdf"];
|
|
@@ -285,8 +287,9 @@
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:documentFolder])
|
|
|
[[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:documentFolder] toURL:[NSURL fileURLWithPath:writeFilePath] error:nil];
|
|
|
|
|
|
+ // Decrypt document
|
|
|
NSURL *decryptAllPasswordsURL = [NSURL fileURLWithPath:writeFilePath];
|
|
|
- document = [[CPDFDocument alloc] initWithURL:decryptAllPasswordsURL];
|
|
|
+ CPDFDocument *document = [[CPDFDocument alloc] initWithURL:decryptAllPasswordsURL];
|
|
|
[self.userPasswordURLs addObject:decryptAllPasswordsURL];
|
|
|
|
|
|
[document unlockWithPassword:@"Owner"];
|
|
@@ -393,8 +396,8 @@
|
|
|
[self encryptByUserPassword:self.document];
|
|
|
[self encryptByOwnerPassword:self.document];
|
|
|
[self encryptByAllPasswords:self.document];
|
|
|
- [self unlock:self.document];
|
|
|
- [self decrypt:self.document];
|
|
|
+ [self unlock];
|
|
|
+ [self decrypt];
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"\nDone!\n"];
|
|
|
self.commandLineStr = [self.commandLineStr stringByAppendingString:@"-------------------------------------\n"];
|
|
|
|