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 Object → PdfItem → PdfObject → PdfDictionary → PdfSecurityHandler → PdfStandardSecurityHandler
Implements ICloneable, IEnumerable<KeyValuePair<String, PdfItem>>, IEnumerable
Sets the user password of the document.
public string UserPassword { internal get; set; }
Sets the owner password of the document.
public string OwnerPassword { internal get; set; }
Gets the dictionary containing the elements of this dictionary.
public DictionaryElements Elements { get; }
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; }
Gets the PdfDocument this object belongs to.
public PdfDocument Owner { get; }
Indicates whether the object is an indirect object.
public bool IsIndirect { get; }
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; }
Gets the indirect reference of this object. If the value is null, this object is a direct object.
public PdfReference Reference { get; internal set; }
Gets the indirect reference of this object. Throws if it is null.
public PdfReference ReferenceNotNull { get; }
InvalidOperationException
The indirect reference must be not null here.
Do not encrypt the PDF file. Resets the user and owner password.
public void SetEncryptionToNoneAndResetPasswords()
Set the encryption according to the given parameter.
public void SetEncryption(DefaultEncryption encryption)
encryption
DefaultEncryption
Encrypt with Version 1 (RC4 and a file encryption key length of 40 bits).
public void SetEncryptionToV1()
Encrypt with Version 2 (RC4 and a file encryption key length of more than 40 bits, PDF 1.4).
public void SetEncryptionToV2(int length)
length
Int32
The file encryption key length - a multiple of 8 from 40 to 128 bit.
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()
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)
encryptMetadata
Boolean
The document metadata stream shall be encrypted (default: true).
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)
encryptMetadata
Boolean
The document metadata stream shall be encrypted (default: true).
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)
encryptMetadata
Boolean
The document metadata stream shall be encrypted (default: true).
Returns this SecurityHandler, if it shall be written to PDF (if an encryption is chosen).
internal PdfStandardSecurityHandler GetIfEncryptionActive()
Gets the PermissionsValue with some corrections that shall be done for saving.
internal uint GetCorrectedPermissionsValue()
Decrypts an ObjectStream. ObjectStreams have to be decrypted before document decryption to allow the removing of the compression filter.
internal void DecryptObjectStream(PdfObjectStream objectStream)
objectStream
PdfObjectStream
Decrypts the whole document (except ObjectStreams which are decrypted once when read in).
internal void DecryptDocument()
Has to be called if an indirect PdfObject is entered for encryption/decryption.
internal void EnterObject(PdfObjectID id)
id
PdfObjectID
Should be called if a PdfObject is leaved from encryption/decryption.
internal void LeaveObject()
Decrypts an indirect PdfObject.
internal void DecryptObject(PdfObject value)
value
PdfObject
Encrypts a string.
internal void EncryptString(Byte[]& bytes)
bytes
Byte[]&
The byte representation of the string.
Decrypts a string.
internal void DecryptString(Byte[]& bytes)
bytes
Byte[]&
The byte representation of the string.
Encrypts a stream.
internal void EncryptStream(Byte[]& bytes, PdfDictionary dictionary)
bytes
Byte[]&
The byte representation of the stream.
dictionary
PdfDictionary
The PdfDictionary holding the stream.
Decrypts a stream.
internal void DecryptStream(Byte[]& bytes, PdfDictionary dictionary)
bytes
Byte[]&
The byte representation of the stream.
dictionary
PdfDictionary
The PdfDictionary holding the stream.
Does all necessary initialization for reading and decrypting the document with this security handler.
internal void PrepareForReading()
Does all necessary initialization for encrypting and writing the document with this security handler.
internal void PrepareForWriting()
Checks the password.
internal PasswordValidity ValidatePassword(string inputPassword)
inputPassword
String
Password or null if no password is provided.
internal void WriteObject(PdfWriter writer)
writer
PdfWriter
Gets the encryption (not nullable). Use this in cases where the encryption must be set.
internal PdfEncryptionBase GetEncryption()
Removes all crypt filters from the document.
public void RemoveCryptFilters()
Creates a crypt filter belonging to standard security handler.
public PdfCryptFilter CreateCryptFilter()
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)
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.
Adds a crypt filter to the document.
public void AddCryptFilter(string name, PdfCryptFilter cryptFilter, bool asDefault)
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.
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()
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)
name
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)
name
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)
name
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)
name
String
Resets the explicitly set crypt filter of a dictionary.
public void ResetCryptFilter(PdfDictionary dictionary)
dictionary
PdfDictionary
Sets the dictionary’s explicitly set crypt filter to the Identity crypt filter.
public void SetIdentityCryptFilter(PdfDictionary dictionary)
dictionary
PdfDictionary
Sets the dictionary’s explicitly set crypt filter to the desired crypt filter.
public void SetCryptFilter(PdfDictionary dictionary, string cryptFilterName)
dictionary
PdfDictionary
cryptFilterName
String
Gets the crypt filter that shall be used to decrypt or encrypt the dictionary.
public CryptFilterBase GetCryptFilter(PdfDictionary dictionary)
dictionary
PdfDictionary