ios - 加密后无法解密

时间:2015-03-02 15:38:37

标签: ios pdf encryption nsdata presentviewcontroller

我在解密pdf文件时遇到麻烦,并在加密后用presentViewController显示这些文件。

当我下载pdf文件时,它们的加密方式如下:

 NSData *pdfData = [[NSFileManager defaultManager] contentsAtPath:filePathDocumetFolder];

                    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                    NSString *documents = [paths objectAtIndex:0];
                    NSString *docFolder = [NSString stringWithFormat:@"/Documents/%@", documentFilePath];
                    NSString *filePath = [documents stringByAppendingPathComponent:docFolder];


                    NSString *pdfName = [NSString stringWithString:filename ];
                    NSError *error;
                    NSData *encryptedPdf = [RNEncryptor encryptData:pdfData withSettings:kRNCryptorAES256Settings password:@"A_SECRET_PASSWORD" error:&error];
if(error){
                    NSLog(@"error: %@", error);
                }
                    NSLog(@"where?? FileTra%@", filePath);
                    [encryptedPdf writeToFile:[filePath stringByAppendingPathComponent:pdfName] atomically:YES];

我知道上面的加密工作正常,因为当我使用iExplorer浏览文件系统时,我无法打开文件,因为它们受到保护。

在我的DocumentHandle控制器中,我试图解密它们以便查看它们:

NSDictionary* dict = [command.arguments objectAtIndex:0];

        NSString* urlStr = dict[@"url"];
        NSURL* url = [NSURL URLWithString:urlStr];
        NSString* fileName = [url path];

        NSString* path = [NSTemporaryDirectory() stringByAppendingPathComponent: fileName];

        NSData *dataEn = [[NSFileManager defaultManager] contentsAtPath:[path stringByAppendingPathComponent:fileName]];
        NSLog(@"this to decrypt%@", [path stringByAppendingPathComponent:fileName]);
        NSData *decryp = [RNDecryptor decryptData:dataEn withSettings:kRNCryptorAES256Settings password:@"A_SECRET_PASSWORD" error:nil];
        [decryp writeToURL:[[NSURL alloc] initFileURLWithPath:path] atomically:YES];
        if(decryp){
            NSLog(@"decrypted");
        }else{
            NSLog(@" not decrypted");
        }



        weakSelf.fileUrl = [[NSURL alloc] initFileURLWithPath:path];

出于某种原因,pdf文件没有被解密,即使我接收到NSLog解密,我也会看到空白文件:(

有人能帮帮我吗?谢谢

0 个答案:

没有答案