PDF控件Spire.PDF for .NET【安全】演示:修改加密PDF的密码

修改PDF文件的密码确实是一个理性的选择,尤其是当密码被某人知道并且您的PDF文件不再安全时。Spire.PDF for .NET使您能够用 C#、VB.NET 修改加密 PDF 文件的密码。您可以修改所有者密码和用户密码,并设置访问 PDF 文件时的用户限制。现在请看修改加密PDF密码的过程,如下图:

Spire.PDF for .NET 是一款独立 PDF 控件,用于 .NET 程序中创建、编辑和操作 PDF 文档。使用 Spire.PDF 类库,开发人员可以新建一个 PDF 文档或者对现有的 PDF 文档进行处理,且无需安装 Adobe Acrobat。

E-iceblue功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式**(qun:767755948)**

Spire.PDF for.net下载 Spire.PDF for java下载

从上图中,您可以很容易地发现,第一步是通过所有者密码解密PDF文件。所以原来的所有者密码是必要的。您可以通过以下方法解密:Spire.Pdf.PdfDocument(string filename, string password)

然后,通过重置所有者密码和用户密码来修改密码。Spire.PDFDocument.Security命名空间中的PDFSecurity类不仅可以帮助您设置所有者密码和用户密码,还可以设置用户权限以限制用户访问。

下面是修改加密PDF文件密码的完整代码,请先下载Spire.PDF for .NET并将其安装在系统上,然后再执行以下代码:

[C#]

复制代码
using Spire.Pdf;
using Spire.Pdf.Security;

namespace modify_PDF_passwords
{
class Program
{
static void Main(string[] args)
{

//load a encrypted file and decrypt it
String encryptedPdf = @"..\Encrypt.pdf";
PdfDocument doc = new PdfDocument(encryptedPdf, "e-iceblue");

//reset PDF passwords and set user password permission
doc.Security.OwnerPassword = "Spire.PDF";
doc.Security.UserPassword = "pdfcomponent";
doc.Security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FillFields;

//Save pdf file.
doc.SaveToFile("Encryption.pdf");
doc.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start("Encryption.pdf");

}
}
}

[VB.NET]

复制代码
Imports Spire.Pdf
Imports Spire.Pdf.Security

Namespace modify_PDF_passwords
Class Program
Private Shared Sub Main(args As String())

'load a encrypted file and decrypt it
Dim encryptedPdf As [String] = "..\Encrypt.pdf"
Dim doc As New PdfDocument(encryptedPdf, "e-iceblue")

'reset PDF passwords and set user password permission
doc.Security.OwnerPassword = "Spire.PDF"
doc.Security.UserPassword = "pdfcomponent"
doc.Security.Permissions = PdfPermissionsFlags.Print Or PdfPermissionsFlags.FillFields

'Save pdf file.
doc.SaveToFile("Encryption.pdf")
doc.Close()
'Launching the Pdf file.
System.Diagnostics.Process.Start("Encryption.pdf")

End Sub
End Class
End Namespace

以上便是如何修改加密PDF的密码,如果您有其他问题也可以继续浏览本系列文章,获取相关教程~

相关推荐
AIwenIPgeolocation19 小时前
数据流通合规新基建 隐私计算平台的三重安全防线
安全
华硕广东20 小时前
电脑被捆绑软件缠上?3 步根治:紧急断网 + 深度清理 + 长效防护
科技·安全·技术美术
E_ICEBLUE1 天前
高效压缩 PDF 文件大小(3 大实用的 Python 库)
python·pdf
TG_yunshuguoji1 天前
阿里云国际代理商:如何实现配置跨区域复制?
安全·阿里云·云计算
技术钱1 天前
vue3 封装图片上传预览组件支持docx、excel、pdf、图片、txt格式
vue.js·pdf·excel
kali-Myon1 天前
NewStarCTF2025-Week2-Pwn
算法·安全·gdb·pwn·ctf·栈溢出
胡耀超1 天前
数据安全指南-合规治理 2025 等保2.0测评实施 全球数据保护法规对比 数据分类分级管理 ISO27001与SOC2认证 跨境数据传输合规
安全·数据安全·等保·跨境数据传输合规·数据分类分级管理·等保2.0测评实施·iso27001与soc2认证
fs哆哆1 天前
在VB.NET中,有没有 ?.这个运算符
java·开发语言·.net
xingxing_F1 天前
PDF Protector for mac PDF文档加密解密工具
macos·pdf
985小水博一枚呀1 天前
【AI大模型学习路线】第三阶段之RAG与LangChain——第十九章(实战基于Advanced RAG的PDF问答)系统部署与测试?
人工智能·学习·langchain·pdf