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:
Complete code
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
If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below: