IacDocument.Encrypt256 Method

The Encrypt256 method secures the PDF document with 256-bit encryption and prevents it from unauthorized access. Two passwords, the owner password and user password, are associated to an encrypted PDF document.

 

This method needs special license.  Please, contact our Sales Department for more information

 

Syntax

Visual Basic .NET:

Public Function Encrypt256(ownerPassword As String, userPassword As String, permissions As UInteger) As Boolean

C#:

public bool Encrypt256(string ownerPassword, string userPassword, uint permissions)

 

Parameters

ownerPassword

Owner password is the password for the author of the document.

The owner password is optional and allows the author having this password to do any operation he/she wishes on this document, including modifying its security settings. It can be blank, but the PDF document won' t be fully protected.

useuserPassword

User password is the password for the destination or the user of the document.

The user password is optional and can be one of the following:

User Password Option

Description

A blank password

The user is not prompted for a password when opening a document, but is restricted to the operations allowed by the author.

The same password as the owner

The user is prompted for a password and the author of the document will not be able to open this document as an owner to change its security settings.

A password different from the owner

The user will not be able to open the document unless he/she enters a valid password. When a valid password is entered, the document can be viewed but its usage is `restricted to the operations allowed by the author.

The password dialog can be forced to appear if the SHIFT key is pressed while pressing the open bottom of the "File Open" dialog. This way, the application user can enter the owner password even if the user password is blank.

permissions

Permissions to user:

 

 

 
AES256 Version 5, Revision 5
AES256 Version 5, Revision 6

Permission Type

Value (Hex)

Value (Dec)*

Value (Hex)

Value (Dec)*

No permission.

0xFFFFF0C0

-3904

0x0FFFF0C0

268431552

Enable Printing (low resolution)

0xFFFFF0C0 | 0x000004

-3904 + 4

0x0FFFF0C0 | 0x000004

268431552 + 4

Enable document modification, including document assembly.

0xFFFFF0C0 | 0x000008

-3904 + 8

0x0FFFF0C0 | 0x000008

268431552 + 8

Enable copying text and graphics, and support of accessibility to users with disabilities or for other purposes.

0xFFFFF0C0 | 0x000010

-3904 + 16

0x0FFFF0C0 | 0x000010

268431552 + 16

Enable adding and changing notes, and fill-in existing interactive form fields (including signature fields).

0xFFFF0C0 | 0x000020

-3904 + 32

0x0FFF0C0 | 0x000020

268431552 + 32

Enable only fill-in existing interactive form fields (including signature fields).

0xFFFF0C0 | 0x000100

-3904 + 256

0x0FFF0C0 | 0x000100

268431552 + 256

Enable extraction text and graphics (in support of accessibility to users with disabilities or for other purposes)

0xFFFF0C0 | 0x000200

-3904 + 512

0x0FFF0C0 | 0x000200

268431552 + 512

Enable document assembly which includes: insert, rotate or delete pages and create bookmark or thumbnail images, but not document modification.

0xFFFF0C0 | 0x000400

-3904 + 1024

0x0FFF0C0 | 0x000400

268431552 + 1024

Enable High-Quality Printing, but the if "Enable Printing" has to be enabled.

0xFFFF0C0 | 0x000800

-3904 + 2048

0x0FFF0C0 | 0x000800

268431552 + 2048

(*) NOTE: Converting from HEX DWORD, unsigned and 32-bit unit of data

 

Return Value

Returns Value True if the call succeeded and False otherwise.

The exception Amyuni.PDFCreator.IacException.LicenseKeyError might be generated if the provided license is not valid or wrong.

 

Remarks

In the case of the evaluation version, the passwords are always set to "aaaaaa" (Owner Password) and "bbbbbb" (User Password) and cannot be changed.

 

To combine multiple options, use hexadecimal 0xFFFFF0C0 or decimal -3904 for Revision 5, or 0x0FFFF0C0 or decimal 268431552 for Revision 6, plus the values 4, 8, 16 or 32.

E.g. to enable both printing and adding notes with Revision5, use hexadecimal 0xFFFFF0C0 | 0x000004 |  0x000020, or decimal -3904 + 4 + 32 = -28. To disable all 4 options, use hexadecimal 0xFFFFF0C0 or decimal -3904.

 

E.g. to enable both printing and adding notes with Revision6, use hexadecimal 0x0FFFF0C0 | 0x000004 |  0x000020 or decimal 268431552 + 4 + 32 = 268431588. To disable all 4 options, use hexadecimal 0x0FFFF0C0 or decimal 268431552.

 

 

Member of Amyuni.PDFCreator.IacDocument.

 

 

Example

<Flags()>

Public Enum PERMISSIONS As Integer

    NO_PERMISSION_R5 = &HFFFFF0C0

    NO_PERMISSION_R6 = &H0FFFF0C0

    ENABLE_PRINTING = &H4

    ENABLE_DOCUMENT_MODIFICATION = &H8

    ENABLE_COPYING_TEXT_GRAPHICS = &H10

    ENABLE_ADDING_CHANGING_NOTES = &H20

    ENABLE_ONLY_FILL_IN = &H100

    ENABLE_EXTRACTION = &H200

    ENABLE_ONLY_ASSEMBLY = &H400

    ENABLE_HIGH_QUALITY = &H800

End Enum

 

Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF Creator .NET Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B"

 

    ' Initialize library

    ' This should be done once

    acPDFCreatorLib.Initialize()

 

    ' set license key This is needed only with licensed version

    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode)

 

    ' Create a new PDF document

    Dim doc As New Amyuni.PDFCreator.IacDocument()

 

    ' Create page object

    Dim page As Amyuni.PDFCreator.IacPage

 

    ' Define first page of PDF document

    page = doc.GetPage(1)

 

    ' Switch to design mode before adding objects to the document

    doc.ReportState = Amyuni.PDFCreator.IacReportState.acReportStateDesign

 

    ' Create a Text

    With page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypeText, "Text1")

        .Attribute("Left").Value = 1000

        .Attribute("Top").Value = 0

        .Attribute("Right").Value = 3250

        .Attribute("Bottom").Value = 500

        .Attribute("Text").Value = "Amyuni Technologies"

        .Attribute("Single line").Value = True

    End With

 

    ' Switch to run mode after objects to the document

    doc.ReportState = Amyuni.PDFCreator.IacReportState.acReportStateRun

 

    ' Encryption

    Dim ownerPassword As String = "owner"

    Dim userPassword As String = "user"

    Dim permissions As UInteger = PERMISSIONS.NO_PERMISSION_R5 Or PERMISSIONS.ENABLE_PRINTING Or PERMISSION.ENABLE_HIGH_QUALITY

    doc.Encrypt256(ownerPassword, userPassword, permissions)

 

    ' Create new stream object

    Dim fileWrite As System.IO.Stream = System.IO.File.OpenWrite("C:\temp\CreatePDFDocument_resulting.pdf")

 

    ' Save stream

    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView)

 

    ' Close the stream

    fileWrite.Close()

 

    ' terminate library to free resources

    acPDFCreatorLib.Terminate()

End Sub

[Flags]

public enum PERMISSIONS

{

    NO_PERMISSION_R5 = unchecked((int)0xFFFFF0C0),

    NO_PERMISSION_R6 = 0x0FFFF0C0,

    ENABLE_PRINTING = 0x4,

    ENABLE_DOCUMENT_MODIFICATION = 0x8,

    ENABLE_COPYING_TEXT_GRAPHICS = 0x10,

    ENABLE_ADDING_CHANGING_NOTES = 0x20,

    ENABLE_ONLY_FILL_IN = 0x100,

    ENABLE_EXTRACTION = 0x200,

    ENABLE_ONLY_ASSEMBLY = 0x400,

    ENABLE_HIGH_QUALITY = 0x800

}

 

static void Sample()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF Creator .NET Evaluation";

    const string strActivationCode = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B";

 

    // Initialize library

    // This should be done once

    acPDFCreatorLib.Initialize();

 

    // set license key This is needed only with licensed version

    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode);

 

    // Create a new PDF document

    Amyuni.PDFCreator.IacDocument doc = new Amyuni.PDFCreator.IacDocument();

 

    // Create page object

    Amyuni.PDFCreator.IacPage page;

 

    // Define first page of PDF document

    page = doc.GetPage(1);

 

    // Switch to design mode before adding objects to the document

    doc.ReportState = Amyuni.PDFCreator.IacReportState.acReportStateDesign;

 

    // Create a Text

    using (Amyuni.PDFCreator.IacObject oText = page.CreateObject(Amyuni.PDFCreator.IacObjectType.acObjectTypeText, "Text1"))

    {

        oText.Attribute("Left").Value = 1000;

        oText.Attribute("Top").Value = 0;

        oText.Attribute("Right").Value = 3250;

        oText.Attribute("Bottom").Value = 500;

        oText.Attribute("Text").Value = "Amyuni Technologies";

        oText.Attribute("Single line").Value = true;

    }

 

    // Encryption

    string ownerPassword = "owner";

    string userPassword = "user";

    uint permissions = unchecked((uint)(PERMISSIONS.NO_PERMISSION_R5 | PERMISSIONS.ENABLE_PRINTING | PERMISSIONS.HIGH_QUALITY));

    doc.Encrypt256(ownerPassword, userPassword, permissions);

 

    // Switch to run mode after objects to the document

    doc.ReportState = Amyuni.PDFCreator.IacReportState.acReportStateRun;

 

    // Create new stream object

    System.IO.FileStream fileWrite = new System.IO.FileStream(@"C:\temp\CreatePDFDocument_resulting.pdf",

    System.IO.FileMode.Create,

    System.IO.FileAccess.Write,

    System.IO.FileShare.Read);

 

    // Save stream

    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView);

 

    // Close the stream

    fileWrite.Close();

 

    // terminate library to free resources

    acPDFCreatorLib.Terminate();

}