欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C# 對PDF文檔加密、解密(基于Spire.Cloud.SDK for .NET)

 更新時間:2020年07月17日 15:07:10   作者:E-iceblue  
這篇文章主要介紹了C# 基于Spire.Cloud.SDK for .NET對PDF文檔進行加密解密,文中講解非常細(xì)致,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下

Spire.Cloud.SDK for .NET提供了接口PdfSecurityApi可用于加密、解密PDF文檔。本文將通過C#代碼演示具體加密及解密方法。

使用工具:

  • Spire.Cloud.SDK for .NET
  • Visual Studio

必要步驟:

步驟一:

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);
    }    
  }
}

生成的文檔打開時,需要輸入密碼。

文檔加密結(jié)果:

【示例2】解密PDF文檔

這里以上文中生成的加密PDF為測試文檔。

using System;
using Spire.Cloud.Pdf.Sdk.Client;
using Spire.Cloud.Pdf.Sdk.Api;

namespace Decrypt
{
  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 = "Encrypt.pdf";//源文檔
      string destFilePath = "pdfsecurity/Decrypt.pdf";//結(jié)果文檔路徑(pdfsecurity為結(jié)果文檔所在文件夾)
      string password = "321";//文檔密碼(這里需要使用的是ownerpassword)
      string folder = "pdfsecurity";//源文檔所在文件夾
      string storage = null;

      //調(diào)用方法解密文檔
      PdfSecurityApi.DecryptDocumentInStorage(name,destFilePath,password,folder,storage);
    }   
  }
}

生成的文檔將不再有密碼保護。

以上就是C# 對PDF文檔加密、解密(基于Spire.Cloud.SDK for .NET)的詳細(xì)內(nèi)容,更多關(guān)于C# 對PDF文檔加密、解密的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論