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:
Полный код
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 });
}
}
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
Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже: