Safeguarding Data with Encryption in C# and .NET

In the modern world of information technology, data security is one of the key aspects of software development. Data encryption allows you to ensure confidentiality and protect information from unauthorized access.

In this article, we will look at how you can protect data using encryption in C# and .NET using the SautinSoft.Pdf component.

Below is an example of password encryption of an existing PDF file:

  1. Add SautinSoft.Pdf from NuGet.
  2. Load the PDF document.
  3. Set password-based encryption using the password required to open the PDF document.
  4. Save the PDF document in an encrypted PDF file.

Output result:

Data encryption in C# and .NET using SautinSoft.Pdf components is an effective way to protect confidential information. Using classes .NET Framework and SautinSoft components, developers can easily integrate encryption functions into their applications, thereby ensuring a high level of data security.

Полный код

using System;
using SautinSoft.Pdf;
using System.IO;

class Program
{
    /// <summary>
    /// Password Protection.
    /// </summary>
    /// <remarks>
    /// Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/password-protection.php
    /// </remarks>
    static void Main()
    {
            // Before starting this example, please get a free 100-day trial key:
            // https://sautinsoft.com/start-for-free/

            // Apply the key here:
            // PdfDocument.SetLicense("...");

        using (var document = PdfDocument.Load(Path.GetFullPath(@"..\..\..\simple text.pdf")))
        {
            // Set password-based encryption with password required to open a PDF document.
            document.SaveOptions.SetPasswordEncryption().DocumentOpenPassword = "user1234";

            // Save PDF document to an encrypted PDF file.
            document.Save("SautinSoft.pdf");
        }

        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("SautinSoft.pdf") { UseShellExecute = true });
    }
}

Download

Option Infer On

Imports System
Imports SautinSoft.Pdf
Imports System.IO

Friend Class Program
	''' <summary>
	''' Password Protection.
	''' </summary>
	''' <remarks>
	''' Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/password-protection.php
	''' </remarks>
	Shared Sub Main()
			' Before starting this example, please get a free 100-day trial key:
			' https://sautinsoft.com/start-for-free/

			' Apply the key here:
			' PdfDocument.SetLicense("...");

		Using document = PdfDocument.Load(Path.GetFullPath("..\..\..\simple text.pdf"))
			' Set password-based encryption with password required to open a PDF document.
			document.SaveOptions.SetPasswordEncryption().DocumentOpenPassword = "user1234"

			' Save PDF document to an encrypted PDF file.
			document.Save("SautinSoft.pdf")
		End Using

		System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("SautinSoft.pdf") With {.UseShellExecute = True})
	End Sub
End Class

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.