Aspose.Pdf

Set Encryption upto 128 Bits

Encryption is one of the famous security measures that is most widely being used in IT industry. Encryption is applied to PDF documents to make them more secure. One of the famous definition of encryption on the web is:

 

"Any procedure used in cryptography to convert plaintext into ciphertext in order to prevent anyone except the intended recipient from reading that data. There are many types of data encryption, and they are the basis of network security. Common types include Data Encryption Standard and public-key encryption."

 

By default, Aspose.Pdf applies encryption level to 40 bits on PDF documents. But if developers like to make their documents more secure then 128 bit encryption is also supported by Aspose.Pdf .

Security class in Aspose.Pdf provides Is128BitsEncrypted property . Is128BitsEncrypted property is a boolean property and can be set to true to apply 128 bit encryption on the PDF documents.

 

Code Snippet

 

[C#]

 

//Instantiate Pdf instance by calling its empty constructor

Pdf pdf1 = new Pdf();

 

//Assign a security instance to Pdf object

pdf1.Security = new Security();

 

//Set encryption level to 128 bits

pdf1.Security.Is128BitsEncrypted = true;

 

//Add a section in the Pdf

Section sec1 = pdf1.Sections.Add();

 

//Create a text paragraph                          

Text text1 = new Text(sec1,"this is text content");

 

//Set the top maring of text paragraph to 30

text1.Margin.Top = 30;

 

//Add the text paragraph to the section

sec1.Paragraphs.Add(text1);

 

//Save the Pdf                          

pdf1.Save(...);

 

[VB.NET]

 

'Instantiate Pdf instance by calling its empty constructor

Dim pdf1 As Pdf =  New Pdf()

 

'Assign a security instance to Pdf object

pdf1.Security = New Security()

 

'Set encryption level to 128 bits

pdf1.Security.Is128BitsEncrypted = True

 

'Add a section in the Pdf

Dim sec1 As Section =  pdf1.Sections.Add()

 

'Create a text paragraph

Dim text1 As Text =  New Text(sec1,"this is text content")

 

'Set the top maring of text paragraph to 30

text1.Margin.Top = 30

 

'Add the text paragraph to the section

sec1.Paragraphs.Add(text1)

 

 

'Save the Pdf

pdf1.Save(...)

 

[JAVA]

 

//Instantiate Pdf object by calling its empty constructor

Pdf pdf1 = new Pdf();

 

//Assign a security instance to Pdf object

pdf1.setSecurity( new Security() );

 

//Set encryption level to 128 bits

pdf1.getSecurity().Set128BitsEncrypted(true);                                         

 

//Add a section in the Pdf

Section sec1 = pdf1.getSections().add();

 

//Create a text paragraph

Text text1 = new Text(sec1,"this is text content");

 

//Set the top maring of text paragraph to 30

text1.getMargin().setTop(30);

 

//Add the text paragraph to the section                                         

sec1.getParagraphs().add(text1);

 

//Save the Pdf

FileOutputStream fileOut = new FileOutputStream(...));

pdf1.save(fileOut);

 

[XML]

 

<?xml version="1.0" encoding="utf-8" ?>

  <Pdf xmlns="Aspose.Pdf" Is128BitsEncrypted="true">

   <Section>

           <Text MarginTop="30">

                   <Segment>this is text content</Segment>

           </Text>

   </Section>

  </Pdf>