Table of Contents

Class PdfEncryption

Namespace
iTextSharp.text.pdf
Assembly
iTextSharp.LGPLv2.Core.dll

@author Paulo Soares (psoares@consiste.pt) and some of it has been ported from https://github.com/LibrePDF/OpenPDF/pull/802

public class PdfEncryption
Inheritance
PdfEncryption
Inherited Members

Constructors

PdfEncryption()

public PdfEncryption()

PdfEncryption(PdfEncryption)

public PdfEncryption(PdfEncryption enc)

Parameters

enc PdfEncryption

Fields

AES_128

public const int AES_128 = 4

Field Value

int

AES_256_V3

public const int AES_256_V3 = 6

Field Value

int

PublicKeyHandler

The public key security handler for certificate encryption

protected PdfPublicKeySecurityHandler PublicKeyHandler

Field Value

PdfPublicKeySecurityHandler

STANDARD_ENCRYPTION_128

public const int STANDARD_ENCRYPTION_128 = 3

Field Value

int

STANDARD_ENCRYPTION_40

public const int STANDARD_ENCRYPTION_40 = 2

Field Value

int

Properties

FileId

public PdfObject FileId { get; }

Property Value

PdfObject

Methods

AddRecipient(X509Certificate, int)

public void AddRecipient(X509Certificate cert, int permission)

Parameters

cert X509Certificate
permission int

CalculateStreamSize(int)

public int CalculateStreamSize(int n)

Parameters

n int

Returns

int

ComputeUserPassword(byte[])

public byte[] ComputeUserPassword(byte[] ownerPassword)

Parameters

ownerPassword byte[]

Returns

byte[]

CreateDocumentId()

public static byte[] CreateDocumentId()

Returns

byte[]

CreateInfoId(byte[])

public static PdfObject CreateInfoId(byte[] id)

Parameters

id byte[]

Returns

PdfObject

DecryptAndCheckPerms(byte[])

implements step f of Algorithm 2.A: Retrieving the file encryption key from an encrypted document in order to decrypt it (revision 6 and later) - ISO 32000-2 section 7.6.4.3.3

public bool DecryptAndCheckPerms(byte[] permsValue)

Parameters

permsValue byte[]

Returns

bool

DecryptByteArray(byte[])

public byte[] DecryptByteArray(byte[] b)

Parameters

b byte[]

Returns

byte[]

EncryptByteArray(byte[])

public byte[] EncryptByteArray(byte[] b)

Parameters

b byte[]

Returns

byte[]

GetCryptoMode()

public int GetCryptoMode()

Returns

int

GetDecryptor()

public StandardDecryption GetDecryptor()

Returns

StandardDecryption

GetEncryptionDictionary()

public PdfDictionary GetEncryptionDictionary()

Returns

PdfDictionary

GetEncryptionStream(Stream)

public OutputStreamEncryption GetEncryptionStream(Stream os)

Parameters

os Stream

Returns

OutputStreamEncryption

HashAlg2B(byte[], byte[], byte[])

implements Algorithm 2.B: Computing a hash (revision 6 and later) - ISO 32000-2 section 7.6.4.3.4

public static byte[] HashAlg2B(byte[] input, byte[] salt, byte[] userKey)

Parameters

input byte[]
salt byte[]
userKey byte[]

Returns

byte[]

IsEmbeddedFilesOnly()

Indicates if only the embedded files have to be encrypted. @since 2.1.3

public bool IsEmbeddedFilesOnly()

Returns

bool

if true only the embedded files will be encrypted

IsMetadataEncrypted()

public bool IsMetadataEncrypted()

Returns

bool

SetCryptoMode(int, int)

public void SetCryptoMode(int mode, int kl)

Parameters

mode int
kl int

SetHashKey(int, int)

public void SetHashKey(int number, int generation)

Parameters

number int
generation int

SetupAllKeys(byte[], byte[], int)

gets keylength and revision and uses revison to choose the initial values for permissions

public void SetupAllKeys(byte[] userPassword, byte[] ownerPassword, int permissions)

Parameters

userPassword byte[]
ownerPassword byte[]
permissions int

SetupByEncryptionKey(byte[], int)

public void SetupByEncryptionKey(byte[] key, int keyLength)

Parameters

key byte[]
keyLength int

SetupByOwnerPassword(byte[], byte[], byte[], byte[], byte[], byte[], int)

implements step d of Algorithm 2.A: Retrieving the file encryption key from an encrypted document in order to decrypt it (revision 6 and later) - ISO 32000-2 section 7.6.4.3.3

public void SetupByOwnerPassword(byte[] documentId, byte[] ownerPassword, byte[] uValue, byte[] ueValue, byte[] oValue, byte[] oeValue, int permissions)

Parameters

documentId byte[]
ownerPassword byte[]
uValue byte[]
ueValue byte[]
oValue byte[]
oeValue byte[]
permissions int

SetupByOwnerPassword(byte[], byte[], byte[], byte[], int)

public void SetupByOwnerPassword(byte[] documentId, byte[] ownerPassword, byte[] userKey, byte[] ownerKey, int permissions)

Parameters

documentId byte[]
ownerPassword byte[]
userKey byte[]
ownerKey byte[]
permissions int

SetupByUserPassword(byte[], byte[], byte[], byte[], byte[], byte[], int)

implements step e of Algorithm 2.A: Retrieving the file encryption key from an encrypted document in order to decrypt it (revision 6 and later) - ISO 32000-2 section 7.6.4.3.3

public void SetupByUserPassword(byte[] documentId, byte[] userPassword, byte[] uValue, byte[] ueValue, byte[] oValue, byte[] oeValue, int permissions)

Parameters

documentId byte[]
userPassword byte[]
uValue byte[]
ueValue byte[]
oValue byte[]
oeValue byte[]
permissions int

SetupByUserPassword(byte[], byte[], byte[], int)

public void SetupByUserPassword(byte[] documentId, byte[] userPassword, byte[] ownerKey, int permissions)

Parameters

documentId byte[]
userPassword byte[]
ownerKey byte[]
permissions int