創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
小編這次要給大家分享的是詳解C#對PDF文檔加密與解密,文章內(nèi)容豐富,感興趣的小伙伴可以來了解一下,希望大家閱讀完這篇文章之后能夠有所收獲。
Spire.Cloud.SDK for .NET提供了接口PdfSecurityApi可用于加密、解密PDF文檔。本文將通過C#代碼演示具體加密及解密方法。
使用工具:
必要步驟:
步驟一:
dll文件獲取及導(dǎo)入。在程序中通過Nuget搜索下載,直接導(dǎo)入所有dll。
導(dǎo)入效果如下如所示:
步驟二:
App ID及Key獲取。在“我的應(yīng)用”板塊中創(chuàng)建應(yīng)用以獲得App ID及App Key。
步驟三:
源文檔上傳。在“文檔管理”板塊,上傳源文檔。這里可以建文件夾,將文檔存放在文件夾下。不建文件夾時,源文檔及結(jié)果文檔直接保存在根目錄。本文示例中,建了兩個文件夾,分別用于存放源文檔及結(jié)果文檔。(云平臺提供免費1 萬次調(diào)用次數(shù)和 2G 文檔內(nèi)存)
C# 代碼示例
【示例1】加密PDF文檔
using System; using Spire.Cloud.Pdf.Sdk.Client; using Spire.Cloud.Pdf.Sdk.Api; using System.IO; using System.Collections.Generic; namespace Encryt { class Program { //配置賬號信息 static String appId = "App ID"; static String appKey = "App Key"; static String baseUrl = "https://api.e-iceblue.cn"; static Configuration PdfConfiguration = new Configuration(appId, appKey, baseUrl); static PdfSecurityApi PdfSecurityApi = new PdfSecurityApi(PdfConfiguration); static void Main(string[] args) { string name = "sample.pdf";//源文檔 string destFilePath = "pdfsecurity/Encrypt.pdf";//結(jié)果文檔路徑(將結(jié)果文檔存放在pdfsecurity文件夾下) string userPassword = "123";//設(shè)置用戶密碼 string ownerPassword = "321";//設(shè)置所有者密碼 string keySize = "Key40Bit";//設(shè)置keySize(如果不需要設(shè)置,可設(shè)置為null) List<string> permissionsFlags = new List<string>();//設(shè)置permissionsFlags(如果不需要設(shè)置,可設(shè)置為null) permissionsFlags.Add("Print"); string folder = "input";//源文檔所在文件夾 string password = null;//源文檔密碼 string storage = null; //調(diào)用方法加密文檔 PdfSecurityApi.EncryptDocumentInStorage(name,destFilePath,userPassword,ownerPassword,keySize,permissionsFlags,folder,storage,password); } } }
網(wǎng)站題目:詳解C#對PDF文檔加密與解密-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://m.newbst.com/article28/dceccp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、虛擬主機(jī)、網(wǎng)站導(dǎo)航、自適應(yīng)網(wǎng)站、標(biāo)簽優(yōu)化、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容