Protect PDF document with AES 128-bit

Docotic.Pdf Library Help > Samples > Security > Protect PDF document with AES 128-bit

This sample shows how to protect your PDF document with a password using AES 128-bit encryption algorithm.

Specify PdfEncryptionAlgorithm.Aes128Bit for PdfDocument.Encryption property and setup owner, user or both passwords to protect output PDF file with advanced protection offered by AES 128-bit encryption.

CopyC#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class ProtectDocumentWithAes128bit
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            PdfDocument pdf = new PdfDocument();
            pdf.Pages[0].Canvas.DrawString("Hello World!");

            pdf.UserPassword = "user";
            pdf.Encryption = PdfEncryptionAlgorithm.Aes128Bit;

            string pathToFile = "ProtectDocumentWithAes128bit.pdf";
            pdf.Save(pathToFile);
            pdf.Dispose();

            Process.Start(pathToFile);
        }
    }
}
CopyVB.NET
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class ProtectDocumentWithAes128bit
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.


            Dim pdf As New PdfDocument()
            pdf.Pages(0).Canvas.DrawString("Hello World!")

            pdf.UserPassword = "user"
            pdf.Encryption = PdfEncryptionAlgorithm.Aes128Bit

            Dim pathToFile As String = "ProtectDocumentWithAes128bit.pdf"
            pdf.Save(pathToFile)
            pdf.Dispose()

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace