HTML JPG PDF XML DOCX
  Product Family
PDF

Encrypt PDF via .NET SDK

API for encrypting PDF documents using Aspose.PDF Cloud .NET SDK

Get Started

How to encrypt PDF via Cloud .NET SDK

For encrypt PDF documents, we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK assists .NET programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using C#, ASP.NET, or other .NET languages for various cloud platforms.Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


     
    PM> Install-Package Aspose.Pdf-Cloud
     

Steps to encrypt PDF via .NET

Aspose.PDF Cloud developers can easily load & encrypt PDF in just a few lines of code.

  1. Create a new Configuration object with your Application Secret and Key
  2. Create an object to connect to the Cloud API
  3. Upload your encrypted document file
  4. Call API to Encrypt Pdf.
  5. Checks the response and logs the result.
  6. Downloads the updated file for local use.
 

Encrypt PDF using Cloud .NET SDK


    using Aspose.Pdf.Cloud.Sdk.Api;
    using Aspose.Pdf.Cloud.Sdk.Model;

    namespace EncryptDecrypt
    {
        public class EncryptPdf
        {
            private string ToBase64(string str)
            { // Convert string to Base64. 
                var bytes = Encoding.UTF8.GetBytes(str);
                return Convert.ToBase64String(bytes);
            }

            public static async Task Encrypt(EncryptDecryptHelper helper, string documentName, string outputName, string localFolder, string remoteFolder)
            { // Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
		pdfApi = new PdfApi(AppSecret, AppSid);

                using (var file = File.OpenRead(Path.Combine(localFolder, documentName)))
		{ // Upload the local encrypted PDF to cloud storage folder name.
                    FilesUploadResult uploadResponse = await pdfApi.UploadFileAsync(Path.Combine(remoteFolder, documentName), documentName);
                    Console.WriteLine(uploadResponse.Uploaded[0]);
                }

                string userPassword = "User-Password";
                string ownerPassword = "Owner-Password";

                // Encrypt the PDF on cloud storage.
                AsposeResponse response = await pdfApi.PostEncryptDocumentInStorageAsync(
                    documentName,
                    ToBase64(userPassword),
                    ToBase64(ownerPassword),
                    CryptoAlgorithm.AESx256.ToString(),
                    folder: remoteFolder);

                // Checks the response and logs the result.
                if (response == null)
                    Console.WriteLine("EncryptPdf(): Unexpected error!");
                else if (response.Code < 200 || response.Code > 299)
                    Console.WriteLine("EncryptPdf(): Failed to encrypt document.");
                else
                {  // Downloads the updated file for local use.
                    Console.WriteLine("EncryptPdf(): document '{0} successfully encrypted.", documentName);
                    Stream stream = pdfApi.DownloadFile(Path.Combine(remoteFolder, documentName));
                    using var fileStream = File.Create(Path.Combine(localFolder, "encrypt_" + outputName));
                    stream.Position = 0;
                    await stream.CopyToAsync(fileStream);
                    Console.WriteLine("EncryptPdf(): File '{0}' successfully downloaded.", "encrypt_" + outputName);
               }
            }
        }
    }
 

Encrypt PDF

Encrypting a PDF document is a simple yet powerful way to protect sensitive content, ensure privacy, and maintain control over how the document is used. Whether you’re sharing business contracts, financial reports, or personal records, encryption helps safeguard your information from unauthorized access, tampering, or misuse.

By applying encryption and setting appropriate permissions, you enhance the document’s security, ensure compliance with industry regulations, and build trust with your audience. In today’s digital world, PDF encryption is not just a feature—it’s a necessity for responsible data handling. Encrypt PDF documents with Aspose.PDF Cloud .NET SDK.

With our .NET library you can:

  • Add PDF document’s header & footer in text or image format.
  • Add tables & text or image stamps to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free Apps to test the functionality online.

  •