如何使用iTextSharp向PDF文档添加安全且隐藏的附件 [英] How to add a secure and hidden attachment to a PDF document using iTextSharp

查看:99
本文介绍了如何使用iTextSharp向PDF文档添加安全且隐藏的附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用iTextSharp将文件附加到现有的PDF文档中,并且可以使用pdfStamper.AddFileAttachment(...)方法来做到这一点.现在,我想以一种无法隐藏甚至无法直接从PDF检索附件的方式来隐藏/安全附件.只能从代码中检索它.

I want to attach a file to an existing PDF document using iTextSharp and I can able to do it using pdfStamper.AddFileAttachment(...) method. Now I want to make the attachment hidden/secure in a way that no one able to see the attachment and even not able to retrieve it directly from PDF. It should only be retrieved from code.

推荐答案

我不会在文件附件中存储任何必须隐藏的内容.这是一种公共的,众所周知的机制,被多个软件(通过UI)理解和支持.

I wouldn't store anything that has to be hidden in a File Attachment. That's a public, well-known mechanism that is understood and supported by multiple pieces of software (through UI).

如果必须隐藏且安全,我将通过某种方式对其进行加密来保护文件,然后将其全部存储在文档中某个位置的私有CosStream中.最好的方法可能是页面片断词典",它提供了一种在PDF文件中存储产品私有数据的方法.私有数据可以附加到表单,页面或整个文档中.

If it has to be hidden and secure, I would protect the file by encrypting it in some way and then store all of it in a private CosStream somewhere in the document. The best way to do this would likely be the "Page-Piece Dictionaries" which provide a way to store product private data inside a PDF file. Private data can be attached to forms, pages or the document as a whole.

在我的PDF规范版本中,这是第14.5段页片字典".

In my version of the PDF specification, this is paragraph 14.5, Page-Piece Dictionaries.

要包括对OP的关注以及mkl的后续评论,没有设定的期望以任何设定的方式对Page-Piece数据进行编码. Page-Piece词典包含一个"Private"键,该键可以具有任何值(因此该值可以是用于较小数据的字符串,可以是包含多个私人信息的词典,也可以是经过压缩以保留内容的流小).

To include the concern of the OP and mkl's subsequent comment, there is no set expectation that Page-Piece data is encoded in any set way. The Page-Piece Dictionary contains a "Private" key that can have anything as value (so the value can be a string for smaller data, could be a dictionary containing multiple pieces of private information, or could be a stream that is compressed to keep it small).

根据PDF规范:私有(密钥):(可选)适合该合格产品的任何私有数据,通常以字典的形式".在说明中标记通常". PDF规范中的进一步说明阐明,存储的数据类型可以是您想要的任何类型.

From the PDF specification: "Private (key) : (Optional) Any private data appropriate to the conforming product, typically in the form of a dictionary". Remark the "typically" in the description. Further explanation in the PDF specification clarifies that the type of data stored may be anything you want.

这篇关于如何使用iTextSharp向PDF文档添加安全且隐藏的附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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