Skip to main content

RC4128Security

Version: 10.0

cete.dynamicpdf.cryptography.rc4128security

RC4128Security​

Represents RC4 128 bit PDF document security.

public class RC4128Security : Security
Public Class RC4128Security
Inherits Security

Inheritance: Object → Security → RC4128Security

Licensing​

This class is a DynamicPDF Generator Enterprise Edition feature. One of the following licenses is required for non-evaluation usage:

  • DynamicPDF Generator for .NET Enterprise Edition
  • DynamicPDF Merger for .NET Enterprise Edition
  • DynamicPDF ReportWriter for .NET Enterprise Edition
  • DynamicPDF Core Suite for .NET Enterprise Edition

Examples​

The following example will set the RC4 security of the document so that the anyone who logs in with the user password will not be able to edit annotations or form fields.

Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements
Imports ceTe.DynamicPDF.Cryptography

Module MyModule

Sub Main()

' Create a PDF Document
Dim MyDocument As Document = New Document

' Create a Page and add it to the document
Dim MyPage As Page = New Page
MyDocument.Pages.Add(MyPage)

' Create a RC4 128 bit security object
Dim security As RC4128Security = New RC4128Security("owner", "user")

' Set these properties to make form fields read only
security.AllowFormFilling = False
security.AllowEdit = False
security.AllowUpdateAnnotsAndFields = False

' Add the security object to the document
MyDocument.Security = security

' Create and display a label as a reference
Dim text As String = "This document has been encrypted with RC4 128 bit encryption."
MyPage.Elements.Add(New Label(text, 50, 50, 400, 100, Font.Helvetica, 18))

' Save the PDF
MyDocument.Draw("C:\MyDocument.pdf")

End Sub
End Module
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;
using ceTe.DynamicPDF.Cryptography;

public class Example
{
public static void CreatePDF(string outputPath)
{
// Create a PDF Document
Document document = new Document();

// Create a Page and add it to the document
Page page = new Page();
document.Pages.Add( page );

// Create a RC4 128 bit security object
RC4128Security security = new RC4128Security( "owner", "user" );

// Set these properties to make form fields read only
security.AllowFormFilling = false;
security.AllowEdit = false;
security.AllowUpdateAnnotsAndFields = false;

// Add the security object to the document
document.Security = security;

// Create and display a label as a reference
string text = "This document has been encrypted with RC4 128 bit encryption.";
page.Elements.Add( new Label( text, 50, 50, 400, 100, Font.Helvetica, 18 ) );

// Save the PDF
document.Draw( outputPath );
}
}

Remarks​

RC4 128 bit PDF security, with UseCryptFilter property set to false is compatible with PDF version 1.4 or higher and can be read with Adobe Acrobat Reader version 5 or higher. By default UseCryptFilter property is false. RC4 128 bit PDF security with crypt filter is compatible with PDF version 1.5 or higher and can be read with Adobe Acrobat Reader version 6 and higher. Older readers will not be able to read document encrypted with this security. For more details on RC4 128 bit security take a look at the Security topic.

Constructors​

RC4128Security()​

Initializes a new instance of the RC4128Security class.

public RC4128Security()
Public Sub New ()

RC4128Security(String)​

Initializes a new instance of the RC4128Security class.

public RC4128Security(string password)
Public Sub New (password As String)

Parameters​

The owner password to open the document.

RC4128Security(String, String)​

Initializes a new instance of the RC4128Security class.

public RC4128Security(string ownerPassword, string userPassword)
Public Sub New (ownerPassword As String, userPassword As String)

Parameters​

The owner password to open the document.

The user password to open the document.

Properties​

AllowAccessibility​

Gets or sets if accessibility programs should be able to read the documents text and images for the user.

public bool AllowAccessibility { get; set; }
Public Property AllowAccessibility As Boolean

Property Value​

Boolean

AllowCopy​

Gets or sets if text and images can be copied to the clipboard by the user. (Inherited from Security)

public bool AllowCopy { get; set; }
Public Property AllowCopy As Boolean

Property Value​

Boolean

AllowDocumentAssembly​

Gets or sets if the document can be assembled and manipulated by the user.

public bool AllowDocumentAssembly { get; set; }
Public Property AllowDocumentAssembly As Boolean

Property Value​

Boolean

AllowEdit​

Gets or sets if the document can be edited by the user. (Inherited from Security)

public bool AllowEdit { get; set; }
Public Property AllowEdit As Boolean

Property Value​

Boolean

AllowFormFilling​

Gets or sets if form filling should be allowed by the user.

public bool AllowFormFilling { get; set; }
Public Property AllowFormFilling As Boolean

Property Value​

Boolean

AllowHighResolutionPrinting​

Gets or sets if the document can be printed at a high resolution by the user.

public bool AllowHighResolutionPrinting { get; set; }
Public Property AllowHighResolutionPrinting As Boolean

Property Value​

Boolean

AllowPrint​

Gets or sets if the document can be printed by the user. (Inherited from Security)

public bool AllowPrint { get; set; }
Public Property AllowPrint As Boolean

Property Value​

Boolean

AllowUpdateAnnotsAndFields​

Gets or sets if annotations and form fields can be added, edited and modified by the user. (Inherited from Security)

public bool AllowUpdateAnnotsAndFields { get; set; }
Public Property AllowUpdateAnnotsAndFields As Boolean

Property Value​

Boolean

EncryptMetadata​

Gets or sets if the document metadata to be encrypted. Valid only when UseCryptFilter property is true.

public bool EncryptMetadata { get; set; }
Public Property EncryptMetadata As Boolean

Property Value​

Boolean

Examples​

This example shows how to encrypt a document using RC4 128 bit encryption excluding metadata.

Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements
Imports ceTe.DynamicPDF.Cryptography
Imports ceTe.DynamicPDF.Xmp

Module MyModule

Sub Main()

'Create a PDF Document
Dim document As Document = New Document

'Create a Page and add it to the document
Dim page As Page = New Page
document.Pages.Add(page)

'Create a RC4 128 bit security object
Dim security As RC4128Security = New RC4128Security("owner", "user")

' Set UseCryptFilter property to true
security.UseCryptFilter = True

' Set EncryptMetadata property to false
security.EncryptMetadata = False

' Add the security object to the document
document.Security = security

'Create and display a label as a reference
Dim text As String = "This document has been encrypted with RC4 128 bit encryption."
page.Elements.Add(New Label(text, 50, 50, 400, 100, Font.Helvetica, 18))

'Create an Xmp Metadata
Dim xmp As XmpMetadata = New XmpMetadata

'Dublin Core Schema.
Dim dc As DublinCoreSchema = xmp.DublinCore
dc.Contributors.Add("Abc")
dc.Contributors.Add("Xyz")
dc.Contributors.Add("Pqrs")
dc.Coverage = "To test all the attributes of schema's provided"
dc.Creators.Add("MyProduct")
dc.Creators.Add("MyCompany")
dc.Date.Add(DateTime.Now)
dc.Description.AddLang("en-us", "XMP Schema's test")
dc.Identifier = "First XMP pdf"
dc.Publisher.Add("mydomain.com")
dc.Publisher.Add("MyCompany")
dc.Relation.Add("test pdf with xmp")
dc.Rights.DefaultText = "US English"
dc.Rights.AddLang("en-us", "All rights reserved 2012, MyCompany.")
dc.Source = "XMP Project"
dc.Subject.Add("eXtensible Metadata Platform")
dc.Title.AddLang("en-us", "XMP")
dc.Title.AddLang("it-it", "XMP - Piattaforma Estendible di Metadata")
dc.Title.AddLang("du-du", "De hallo Wereld")
dc.Title.AddLang("fr-fr", "XMP - Une Platforme Extensible pour les M�t�donn�es")
dc.Title.AddLang("DE-DE", "���� Hallo Welt")
dc.Type.Add("Pdf file containing xmp metadata")

'Basic Schema.
Dim bs As BasicSchema = xmp.BasicSchema
bs.Advisory.Add("Date")
bs.Advisory.Add("Contributors")
bs.Nickname = "xyz"

'Rights Management Schema.
Dim rm As RightsManagementSchema = New RightsManagementSchema
rm.Marked2 = CopyrightStatus.PublicDomain
rm.Owner.Add("MyCompany")
rm.UsageTerms.AddLang("en-us", "Contact MyCompany")
xmp.AddSchema(rm)

'Basic Job Ticket Schema.
Dim job As BasicJobTicketSchema = New BasicJobTicketSchema
job.JobRef.Add("MyCompany", "Xmp Test", New Uri("http://www.mydomain.com/"))
job.JobRef.Add("MyCompany", "XMP Metadata", New Uri("http://www.mydomain.com/"))
xmp.AddSchema(job)

'Paged-Text Schema.
Dim pt As PagedTextSchema = New PagedTextSchema
xmp.AddSchema(pt)

'Add the Xmp Metadata to the document
document.XmpMetadata = xmp

' Save the PDF
document.Draw(outputPath)

End Sub
End Module
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;
using ceTe.DynamicPDF.Cryptography;
using ceTe.DynamicPDF.Xmp;

public class Example
{
public static void CreatePDF(string outputPath)
{
// Create a PDF Document
Document document = new Document();

// Create a Page and add it to the document
Page page = new Page();
document.Pages.Add( page );

// Create a RC4 128 bit security object
RC4128Security security = new RC4128Security( "owner", "user" );

// Set UseCryptFilter property to true
security.UseCryptFilter = true;

// Set EncryptMetadata property to false
security.EncryptMetadata = false;

// Add the security object to the document
document.Security = security;

// Create and display a label as a reference
string text = "This document has been encrypted with RC4 128 bit encryption.";
page.Elements.Add( new Label( text, 50, 50, 400, 100, Font.Helvetica, 18 ) );

// Create an Xmp Metadata
XmpMetadata xmp = new XmpMetadata();

// Dublin Core Schema.
DublinCoreSchema dc = xmp.DublinCore;
dc.Contributors.Add( "Abc" );
dc.Contributors.Add( "Xyz" );
dc.Contributors.Add( "Pqrs" );
dc.Coverage = "To test all the attributes of schema's provided";
dc.Creators.Add( "MyProduct" );
dc.Creators.Add( "MyCompany" );
dc.Date.Add( DateTime.Now );
dc.Description.AddLang( "en-us", "XMP Schema's test" );
dc.Identifier = "First XMP pdf";
dc.Publisher.Add( "mydomain.com" );
dc.Publisher.Add( "MyCompany" );
dc.Relation.Add( "test pdf with xmp" );
dc.Rights.DefaultText = "US English";
dc.Rights.AddLang( "en-us", "All rights reserved 2012, MyCompany." );
dc.Source = "XMP Project";
dc.Subject.Add( "eXtensible Metadata Platform" );
dc.Title.AddLang( "en-us", "XMP" );
dc.Title.AddLang( "it-it", "XMP - Piattaforma Estendible di Metadata" );
dc.Title.AddLang( "du-du", "De hallo Wereld" );
dc.Title.AddLang( "fr-fr", "XMP - Une Platforme Extensible pour les Métédonnées" );
dc.Title.AddLang( "DE-DE", "ÄËßÜ Hallo Welt" );
dc.Type.Add( "Pdf file containing xmp metadata" );
// Basic Schema.
BasicSchema bs = xmp.BasicSchema;
bs.Advisory.Add( "Date" );
bs.Advisory.Add( "Contributors" );
bs.Nickname = "xyz";
// Rights Management Schema.
RightsManagementSchema rm = new RightsManagementSchema();
rm.Marked2 = CopyrightStatus.PublicDomain;
rm.Owner.Add( "MyCompany" );
rm.UsageTerms.AddLang( "en-us", "Contact MyCompany" );
xmp.AddSchema( rm );
// Basic Job Ticket Schema.
BasicJobTicketSchema job = new BasicJobTicketSchema();
job.JobRef.Add( "MyCompany", "Xmp Test", new Uri( "http://www.mydomain.com/" ) );
job.JobRef.Add( "MyCompany", "XMP Metadata", new Uri( "http://www.mydomain.com/" ) );
xmp.AddSchema( job );

// Paged-Text Schema.
PagedTextSchema pt = new PagedTextSchema();
xmp.AddSchema(pt);

// Add the Xmp Metadata to the document
document.XmpMetadata = xmp;

// Save the PDF
document.Draw( outputPath );
}
}

OwnerPassword​

Gets or sets the owner password. (Inherited from Security)

public string OwnerPassword { get; set; }
Public Property OwnerPassword As String

Property Value​

String

UseCryptFilter​

Gets or sets if the encryption should be done with crypt filters.

public bool UseCryptFilter { get; set; }
Public Property UseCryptFilter As Boolean

Property Value​

Boolean

Remarks​

The default value is false. If set to true RC4 128 bit encryption is compatible with PDF version 1.5 or higher and can be read with Adobe Acrobat Reader version 6 or higher. Without crypt filter RC4 128 bit encryption is compatible with PDF version 1.4 or higher and can be read with Adobe Acrobat Reader version 5 or higher.

UserPassword​

Gets or sets the user password. (Inherited from Security)

public string UserPassword { get; set; }
Public Property UserPassword As String

Property Value​

String

Methods​

Draw(DocumentWriter, Encrypter)​

Draws the encrypter dictionary to the given DocumentWriter object.

public void Draw(DocumentWriter writer, Encrypter encrypter)
Sub Draw(writer As DocumentWriter, encrypter As Encrypter)

Parameters​

DocumentWriter object to receive the output.

Encrypter object used to encrypt the document.

Equals(Object)​

Determines whether the specified Object is equal to the current Object . (Inherited from Object)

public bool Equals(Object obj)
Function Equals(obj As Object) As Boolean

Parameters​

The Object to compare with the current Object .

Returns​

true if the specified Object is equal to the current Object ; otherwise, false.

GetEncrypter(Byte[])​

Gets a 128 bit Encrypter object to be used for encrypting the document.

public Encrypter GetEncrypter(Byte[] id)
Function GetEncrypter(id As Byte()) As Encrypter

Parameters​

ID of the current PDF document.

Returns​

An Encrypter .

GetHashCode()​

Serves as a hash function for a particular type. (Inherited from Object)

public int GetHashCode()
Function GetHashCode() As Integer

Returns​

A hash code for the current Object .

GetType()​

Gets the Type of the current instance. (Inherited from Object)

public Type GetType()
Function GetType() As Type

Returns​

The Type instance that represents the exact runtime type of the current instance.

ToString()​

Returns a String that represents the current Object . (Inherited from Object)

public string ToString()
Function ToString() As String

Returns​

A String that represents the current Object .

See Also​

ceTe.DynamicPDF.Cryptography