如何“加载”使用 Quartz 以 mmap() 方式加密 (AES-256) PDF 文件?
是的,我知道这个问题有点绕口...
我的磁盘上有一个 PDF 文件,该文件已加密(AES-256,使用 CommonCrypto/OpenSSL)。 我想使用 Quartz 的 CGPDF... 函数渲染 PDF,并发现可以使用 CGDataProvider 创建 CGPDFDocument。
我想知道是否可以为 CGDataProvider 创建回调,以解密并仅加载 Quartz PDF 渲染器所需的内存块。从安全/隐私的角度来看,我宁愿不将解密的文件写入磁盘。
有什么想法吗?
希望我能开始一次“开明”的审判& stackoverflow 社区的输入错误:)
Yes, I know this question is kind of a mouthful of everything...
I have a PDF file on disk, which is encrypted (AES-256, using CommonCrypto/OpenSSL).
I'd like to render the PDF using Quartz' CGPDF... functions and found it's possible to create a CGPDFDocument with a CGDataProvider.
I'm wondering whether it's possible to create callbacks for the CGDataProvider, to decrypt and load only the blocks in memory that Quartz' PDF renderer needs. I'd rather not write the decrypted file to disk from a security/privacy perspective.
Any ideas?
Hopefully I can start an "enlighted" trial & error with the input of stackoverflow's community :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它足够小,您可以将其保存在 NSData 中 - 动态解密并将其存储在内存中。如果规模更大,事情就更困难了。最终,人们还可以解密您的二进制文件并从中提取 AES 密钥。
PDF 的密码保护可能会增加一小层安全性,但它也很容易被规避。
If it's small enough, you can just keep it in an NSData - decrypt it on the fly and store it in memory. If it's larger, things are more difficult. Ultimately, people also can decrypt your binary and extract the AES key out of it.
PDF's password protection may add a small layer of security, but it's also very easy to circumvent.
我们最终所做的是使用
CGDataProviderCreateDirect
API 并实现 C 回调来解密部分加密的 PDF 数据,该数据是使用[NSData dataWithContentsOfMappedFile:]
(使用 mmap () 在引擎盖下)。这使我们能够渲染巨大的加密 PDF,并具有较短的加载时间和较低的内存使用量。What we did eventually is use the
CGDataProviderCreateDirect
API and implemented the C callbacks to decrypt parts of the encrypted PDF data, which was loaded using[NSData dataWithContentsOfMappedFile:]
(which uses mmap() under the hood). This allowed us to render huge encrypted PDFs and having short loading times and low memory usage.