使用QuickLook框架或UiDocumentInteractionController显示加密文件 [英] Display encrypted file using QuickLook framework or UiDocumentInteractionController

查看:200
本文介绍了使用QuickLook框架或UiDocumentInteractionController显示加密文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地存储了加密的word / excel / pdf文件,我需要在iPad应用中预览。我知道QLPreviewController或UiDocumentInteractionController可用于预览这些文件。我可以很好地使用这个

I have an encrypted word/excel/pdf file locally stored which I need to preview in my iPad app. I understand that QLPreviewController or UiDocumentInteractionController could be used to preview these files. I can very well use this

- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index {

    return [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[documents objectAtIndex:index] ofType:nil]];
}

但文件是加密的,当我解密时我会得到NSData目的。我如何在其中任何一个中加载NSData。

But the file is encrypted and when I decrypt it I would get hold of NSData object. How do I go about loading NSData in either of these.

另外我理解我可以很好地将NSData存储为本地文件并将其加载到预览中。但是存在一个限制,即不在本地存储未加密的文件。

Also I understand that I can very well store the NSData back as a local file and load it in Preview. But there is a constraint of not storing the unencrypted file locally.

如果有人已经完成了这项工作并且可以帮助我,我们将不胜感激。

If someone has already accomplished this and can help me out here it will be greatly appreciated.

谢谢
AJ

Thanks AJ

推荐答案

因为你使用快速查看,您的选项有限。您必须提供快速查看 NSURL ,这意味着它必须位于文件系统(或Internet)上。幸运的是,这应该不是什么大问题。 iOS设备使用硬件级加密。当您的文件被加密时,只有您的应用程序具有解密它的密钥。因此,您的文件仍然会被加密,但您的应用程序和您的应用程序也可以读取。

Since you are using Quick Look, your options are limited. You must give Quick Look an NSURL, which means it must be on the file system (or the Internet). Fortunately, this shouldn't be much of a problem. iOS devices use hardware-level encryption. When your file is encrypted, only your app has the key to decrypt it. So, your file will still be encrypted, but it will also be readable by your app and only your app.

以下是您的操作:


  1. 将文件解密为 NSData 对象,您已经完成了。

  1. Decrypt your file into an NSData object, which you've already done.

将文件写入不会上传到iCloud或iTunes备份的位置。 tmp 目录可能是最佳选择。代码如下所示:

Write the file to a location that will not get uploaded to iCloud nor backed up by iTunes. The tmp directory is probably the best choice. The code looks something like this:

NSData * data = // Your decrypted file data.
NSString * fileName = // Whatever you want to name your file.
NSString * path = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];
NSURL * url = [NSURL URLWithString:path];
NSError * error = nil;

BOOL success = [data writeToURL:url
                        options:NSDataWritingFileProtectionComplete
                          error:&error];
if (success) {
    // Give the URL to Quick Look.
}
else {
    // An error happened. See the 'error' object for the details.
}

此时您有一个NSURL可以与<$ c $一起使用c>快速查看。完成后,请不要忘记删除已解密的文件。

At this point you have an NSURL which you can use with Quick Look. Don't forget to delete the decrypted file when you are done with it.

有关磁盘加密的一些注意事项:

There are a few things to note about on-disk encryption:


  1. 仅在iOS 4.0 +上支持。

  1. It is only supported on iOS 4.0+.

它可能不适用于较旧设备。

It may not work on "older" devices.

用户必须拥有有效的密码。

The user must have an active passcode.

如果使用 NSDataWritingFileProtectionComplete ,则在设备锁定时无法访问该文件。如果您需要在应用程序被锁定时访问该文件,那么您应该使用 NSDataWritingFileProtectionCompleteUnlessOpen NSFileProtectionCompleteUntilFirstUserAuthentication 。即使设备被盗和越狱,这仍然会给你很大的保护。但请注意,这些加密选项仅适用于iOS 5.0 +

If you use NSDataWritingFileProtectionComplete, the file is not accessible while the device is locked. If you need to access the file while the app is locked, then you should use NSDataWritingFileProtectionCompleteUnlessOpen or NSFileProtectionCompleteUntilFirstUserAuthentication instead. This will still give you great protection, even if the device is stolen and jailbroken. Be aware, though, that these encryption options are only available on iOS 5.0+

有关磁盘的详细信息加密,请查看 iOS应用程序编程指南

For more details for on-disk encryption, check out the iOS App Programming Guide

这篇关于使用QuickLook框架或UiDocumentInteractionController显示加密文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆