我想在我的MAC应用程序中打开密码保护Microsoft Word文件。
我已经尝试过“AESCrypt”进行保存&打开密码保护文件,但我需要打开手动创建的安全文件。
#import "AESCrypt.h"
- (IBAction) OpenFile: (id) sender{
NSOpenPanel * zOpenPanel = [NSOpenPanel openPanel];
[zOpenPanel setAllowedFileTypes:[NSArray arrayWithObject:[[fileType selectedCell] title]]];
NSInteger zIntResult = [zOpenPanel runModal];
if (zIntResult == NSAlertDefaultReturn) {
NSURL *zUrl = [zOpenPanel URL];
// read the file
txtView.string=@"";
NSString * zStr = [NSString stringWithContentsOfURL:zUrl
encoding:NSASCIIStringEncoding
error:NULL];
[self decryptFile:zStr];
}
// NSLog(@"zStr=\n%@",zStr);
}
- (void) decryptFile : (NSString *) aStrFileContent {
NSAlert *alert = [NSAlert alertWithMessageText:nil
defaultButton:@"Set"
alternateButton:@"Cancel"
otherButton:nil
informativeTextWithFormat:@"Please enter a password to decrypt your file with:"];
[alert setIcon:[NSImage imageNamed:nil]];
NSSecureTextField *input = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
[alert setAccessoryView:input];
NSInteger button = [alert runModal];
if (button == NSAlertDefaultReturn) {
NSString *decyptData = [AESCrypt decrypt:aStrFileContent password:[input stringValue]];
if ([decyptData length] == 0) {
[self alertView:@"Error.." InformationText:@"Please Enter Correct Password to get File Data!!!"];
}
txtView.string = decyptData;
}
}
谢谢!