且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用用户名和密码保护PDF?

更新时间:2022-02-01 15:07:03

使用PDF无法实现所需的功能.

You can't achieve what you want with PDF.

有两种方法来加密PDF文档:

There are two ways to encrypt a PDF document:

  1. 使用密码.您可以定义两个密码:一个用户密码和一个所有者密码.每个收到文档的人都可以打开用所有者密码加密的文档.所有者密码用于定义权限(例如:可以查看文档,但不能打印文档).在不知道所有者密码的情况下删除限制相当容易.当Adobe仍拥有PDF参考文献上的版权时,它曾经是非法的,但是由于PDF现在是ISO标准,因此尚不清楚是否允许应用该规范删除所有者密码.如果使用用户密码对文档进行加密,则知道用户密码的所有人都可以打开该文件.没有用户名,仅 用户密码.
  2. 使用证书.您可以要求您的用户创建一个公钥/私钥对.然后,您可以要求他们将私钥保持私密,并要求他们将您的公钥提供给您.当使用他们的公共证书加密PDF时,您可以使用他们的公共密钥加密文档.从那时起,只有相应私钥的所有者才能阅读文档.但是:相应私钥的所有者也可以解密文档,以便可以共享它.
  1. Using passwords. You can define two passwords: a user password and an owner password. A document that is encrypted with an owner password can be opened by every one who receives the document. The owner password is there to define permissions (for instance: the document can be viewed, but not printed). Removing the restrictions without knowing the owner password is fairly easy. It used to be illegal when Adobe still owned the copyright on the PDF reference, but since PDF is now an ISO standard, it's not entirely clear if applying the spec to remove the owner password is allowed. If a document is encrypted using a user password, everybody who knows the user password can open the file. There is no username, only a user password.
  2. Using certificates. You could ask your users to create a public/private key pair. You could then ask them to keep their private key private and ask them to give you their public key. When you encrypt your PDF using their public certificate, you can then encrypt the document with their public key. From that moment on, only the owner of the corresponding private key can read the document. However: the owner of the corresponding private key can also decrypt the document so that it can be shared.

这两种情况都不符合您的目的(有关详细信息,请阅读ISO-32000-1).唯一的选择是购买昂贵的DRM解决方案.

Neither of both cases serve your purpose (read ISO-32000-1 for the full details). The only alternative is to buy an expensive DRM solution.