PDFsharp-net6

PdfStandardSecurityHandler

Namespace: PdfSharp.Pdf.Security

Represents the standard PDF security handler.

public sealed class PdfStandardSecurityHandler : PdfSecurityHandler, System.ICloneable, System.Collections.Generic.IEnumerable`1[[System.Collections.Generic.KeyValuePair`2[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[PdfSharp.Pdf.PdfItem, PdfSharp, Version=0.1.3.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Collections.IEnumerable

Inheritance ObjectPdfItemPdfObjectPdfDictionaryPdfSecurityHandlerPdfStandardSecurityHandler
Implements ICloneable, IEnumerable<KeyValuePair<String, PdfItem>>, IEnumerable

Properties

UserPassword

Sets the user password of the document.

public string UserPassword { internal get; set; }

Property Value

String

OwnerPassword

Sets the owner password of the document.

public string OwnerPassword { internal get; set; }

Property Value

String

Elements

Gets the dictionary containing the elements of this dictionary.

public DictionaryElements Elements { get; }

Property Value

DictionaryElements

Stream

Gets or sets the PDF stream belonging to this dictionary. Returns null if the dictionary has no stream. To create the stream, call the CreateStream function.

public PdfStream Stream { get; set; }

Property Value

PdfStream

Owner

Gets the PdfDocument this object belongs to.

public PdfDocument Owner { get; }

Property Value

PdfDocument

IsIndirect

Indicates whether the object is an indirect object.

public bool IsIndirect { get; }

Property Value

Boolean

Internals

Gets the PdfInternals object of this document, that grants access to some internal structures which are not part of the public interface of PdfDocument.

public PdfObjectInternals Internals { get; }

Property Value

PdfObjectInternals

Reference

Gets the indirect reference of this object. If the value is null, this object is a direct object.

public PdfReference Reference { get; internal set; }

Property Value

PdfReference

ReferenceNotNull

Gets the indirect reference of this object. Throws if it is null.

public PdfReference ReferenceNotNull { get; }

Property Value

PdfReference

Exceptions

InvalidOperationException
The indirect reference must be not null here.

Methods

SetEncryptionToNoneAndResetPasswords()

Do not encrypt the PDF file. Resets the user and owner password.

public void SetEncryptionToNoneAndResetPasswords()

SetEncryption(DefaultEncryption)

Set the encryption according to the given parameter.

public void SetEncryption(DefaultEncryption encryption)

Parameters

encryption DefaultEncryption

SetEncryptionToV1()

Encrypt with Version 1 (RC4 and a file encryption key length of 40 bits).

public void SetEncryptionToV1()

SetEncryptionToV2(Int32)

Encrypt with Version 2 (RC4 and a file encryption key length of more than 40 bits, PDF 1.4).

public void SetEncryptionToV2(int length)

Parameters

length Int32
The file encryption key length - a multiple of 8 from 40 to 128 bit.

SetEncryptionToV2With128Bits()

Encrypt with Version 2 (RC4 and a file encryption key length of more than 40 bits, PDF 1.4) with a file encryption key length of 128 bits. This was the default encryption in PDFsharp 1.5.

public void SetEncryptionToV2With128Bits()

SetEncryptionToV4UsingRC4(Boolean)

Encrypt with Version 4 (RC4 or AES and a file encryption key length of 128 bits using a crypt filter, PDF 1.5) using RC4.

public void SetEncryptionToV4UsingRC4(bool encryptMetadata)

Parameters

encryptMetadata Boolean
The document metadata stream shall be encrypted (default: true).

SetEncryptionToV4UsingAES(Boolean)

Encrypt with Version 4 (RC4 or AES and a file encryption key length of 128 bits using a crypt filter, PDF 1.5) using AES (PDF 1.6).

public void SetEncryptionToV4UsingAES(bool encryptMetadata)

Parameters

encryptMetadata Boolean
The document metadata stream shall be encrypted (default: true).

SetEncryptionToV5(Boolean)

Encrypt with Version 5 (AES and a file encryption key length of 256 bits using a crypt filter, PDF 2.0).

public void SetEncryptionToV5(bool encryptMetadata)

Parameters

encryptMetadata Boolean
The document metadata stream shall be encrypted (default: true).

GetIfEncryptionActive()

Returns this SecurityHandler, if it shall be written to PDF (if an encryption is chosen).

internal PdfStandardSecurityHandler GetIfEncryptionActive()

Returns

PdfStandardSecurityHandler

GetCorrectedPermissionsValue()

Gets the PermissionsValue with some corrections that shall be done for saving.

internal uint GetCorrectedPermissionsValue()

Returns

UInt32

DecryptObjectStream(PdfObjectStream)

Decrypts an ObjectStream. ObjectStreams have to be decrypted before document decryption to allow the removing of the compression filter.

internal void DecryptObjectStream(PdfObjectStream objectStream)

Parameters

objectStream PdfObjectStream

DecryptDocument()

Decrypts the whole document (except ObjectStreams which are decrypted once when read in).

internal void DecryptDocument()

EnterObject(PdfObjectID)

Has to be called if an indirect PdfObject is entered for encryption/decryption.

internal void EnterObject(PdfObjectID id)

Parameters

id PdfObjectID

LeaveObject()

Should be called if a PdfObject is leaved from encryption/decryption.

internal void LeaveObject()

DecryptObject(PdfObject)

Decrypts an indirect PdfObject.

internal void DecryptObject(PdfObject value)

Parameters

value PdfObject

EncryptString(Byte[]&)

Encrypts a string.

internal void EncryptString(Byte[]& bytes)

Parameters

bytes Byte[]&
The byte representation of the string.

DecryptString(Byte[]&)

Decrypts a string.

internal void DecryptString(Byte[]& bytes)

Parameters

bytes Byte[]&
The byte representation of the string.

EncryptStream(Byte[]&, PdfDictionary)

Encrypts a stream.

internal void EncryptStream(Byte[]& bytes, PdfDictionary dictionary)

Parameters

bytes Byte[]&
The byte representation of the stream.

dictionary PdfDictionary
The PdfDictionary holding the stream.

DecryptStream(Byte[]&, PdfDictionary)

Decrypts a stream.

internal void DecryptStream(Byte[]& bytes, PdfDictionary dictionary)

Parameters

bytes Byte[]&
The byte representation of the stream.

dictionary PdfDictionary
The PdfDictionary holding the stream.

PrepareForReading()

Does all necessary initialization for reading and decrypting the document with this security handler.

internal void PrepareForReading()

PrepareForWriting()

Does all necessary initialization for encrypting and writing the document with this security handler.

internal void PrepareForWriting()

ValidatePassword(String)

Checks the password.

internal PasswordValidity ValidatePassword(string inputPassword)

Parameters

inputPassword String
Password or null if no password is provided.

Returns

PasswordValidity

WriteObject(PdfWriter)

internal void WriteObject(PdfWriter writer)

Parameters

writer PdfWriter

GetEncryption()

Gets the encryption (not nullable). Use this in cases where the encryption must be set.

internal PdfEncryptionBase GetEncryption()

Returns

PdfEncryptionBase

RemoveCryptFilters()

Removes all crypt filters from the document.

public void RemoveCryptFilters()

CreateCryptFilter()

Creates a crypt filter belonging to standard security handler.

public PdfCryptFilter CreateCryptFilter()

Returns

PdfCryptFilter

GetOrAddStandardCryptFilter(Boolean)

Returns the StdCF as it shall be used in encryption version 4 and 5. If not yet existing, it is created regarding the asDefaultIfNew parameter, which will set StdCF as default for streams, strings, and embedded file streams.

public PdfCryptFilter GetOrAddStandardCryptFilter(bool asDefaultIfNew)

Parameters

asDefaultIfNew Boolean
If true and the crypt filter is newly created, the crypt filter is referred to as default for any strings, and streams in StmF, StrF and EFF keys.

Returns

PdfCryptFilter

AddCryptFilter(String, PdfCryptFilter, Boolean)

Adds a crypt filter to the document.

public void AddCryptFilter(string name, PdfCryptFilter cryptFilter, bool asDefault)

Parameters

name String
The name to identify the crypt filter.

cryptFilter PdfCryptFilter
The crypt filter.

asDefault Boolean
If true, the crypt filter is referred to as default for any strings and streams in StmF, StrF and EFF keys.

EncryptEmbeddedFilesOnly()

Encrypts embedded file streams only by setting a crypt filter only in the security handler’s EFF key and setting the crypt filter’s AuthEvent Key to /EFOpen, in order authenticate embedded file streams when accessing the embedded file.

public void EncryptEmbeddedFilesOnly()

SetCryptFilterAsDefault(String)

Sets the given crypt filter as default for streams, strings, and embedded streams. The crypt filter must be manually added crypt filter, “Identity” or null to remove the StmF, StrF and EFF key.

public void SetCryptFilterAsDefault(string name)

Parameters

name String

SetCryptFilterAsDefaultForStreams(String)

Sets the given crypt filter as default for streams. The crypt filter must be manually added crypt filter, “Identity” or null to remove the StmF key.

public void SetCryptFilterAsDefaultForStreams(string name)

Parameters

name String

SetCryptFilterAsDefaultForStrings(String)

Sets the given crypt filter as default for strings. The crypt filter must be manually added crypt filter, “Identity” or null to remove the StrF key.

public void SetCryptFilterAsDefaultForStrings(string name)

Parameters

name String

SetCryptFilterAsDefaultForEmbeddedFileStreams(String)

Sets the given crypt filter as default for embedded file streams. The crypt filter must be manually added crypt filter, “Identity” or null to remove the EFF key.

public void SetCryptFilterAsDefaultForEmbeddedFileStreams(string name)

Parameters

name String

ResetCryptFilter(PdfDictionary)

Resets the explicitly set crypt filter of a dictionary.

public void ResetCryptFilter(PdfDictionary dictionary)

Parameters

dictionary PdfDictionary

SetIdentityCryptFilter(PdfDictionary)

Sets the dictionary’s explicitly set crypt filter to the Identity crypt filter.

public void SetIdentityCryptFilter(PdfDictionary dictionary)

Parameters

dictionary PdfDictionary

SetCryptFilter(PdfDictionary, String)

Sets the dictionary’s explicitly set crypt filter to the desired crypt filter.

public void SetCryptFilter(PdfDictionary dictionary, string cryptFilterName)

Parameters

dictionary PdfDictionary

cryptFilterName String

GetCryptFilter(PdfDictionary)

Gets the crypt filter that shall be used to decrypt or encrypt the dictionary.

public CryptFilterBase GetCryptFilter(PdfDictionary dictionary)

Parameters

dictionary PdfDictionary

Returns

CryptFilterBase