PdfFileSecurity

PdfFileSecurity

Overview

PdfFileSecurity is a class in Aspose.PDF FOSS for .NET. Inherits from: IDisposable.

Facade for encrypting, decrypting, and changing passwords on PDF files.

This class provides 31 methods for working with PdfFileSecurity objects in .NET programs. Available methods include: BindPdf, ChangePassword, ChangePasswords, Close, DecryptFile, Dispose, EncryptFile, PdfFileSecurity, Save, SetPrivilege, TryChangePassword, TryDecryptFile, and 2 additional methods. All public members are accessible to any .NET application after installing the Aspose.PDF FOSS for .NET package. Properties: AllowExceptions, InputFile, InputStream, LastException, OutputFile, OutputStream.

Properties

NameTypeAccessDescription
AllowExceptionsboolRead/WriteWhen true, stateful operations propagate exceptions; when false (the default), Try* operations capture the last thrown exception in LastException and return false.
LastExceptionException?ReadLast exception captured by a Try* method, or null.
InputFilestringRead/WriteSet the input file path used by stateful operations.
InputStreamStreamRead/WriteSet the input stream used by stateful operations.
OutputFilestringRead/WriteRoute the next Save to this file.
OutputStreamStreamRead/WriteRoute the next Save to this stream.

Methods

SignatureDescription
PdfFileSecurity()Default ctor — for the static byte[]-based overloads.
PdfFileSecurity(document: Document)Wrap an existing Document; caller owns its lifetime.
PdfFileSecurity(path: string)Open the file at path and bind it.
PdfFileSecurity(document: Document, outputStream: Stream)Wrap a document and route subsequent saves to outputStream.
PdfFileSecurity(document: Document, outputFile: string)Wrap a document and route subsequent saves to outputFile.
PdfFileSecurity(inputStream: Stream, outputStream: Stream)Bind from a stream and save to a stream.
PdfFileSecurity(inputFile: string, outputFile: string)Bind from a path and save to a path.
Dispose()Calls Dispose on this PdfFileSecurity instance.
Close()Alias for Dispose.
BindPdf(srcFile: string)Bind to a PDF file at srcFile.
BindPdf(srcStream: Stream)Bind to a PDF read from srcStream.
BindPdf(document: Document)Bind to an existing Document; caller owns its lifetime.
Save(path: string)Save the bound document to a file path.
Save(stream: Stream)Save the bound document to a stream.
EncryptFile(userPassword: string, ownerPassword: string, privilege: DocumentPrivilege, keySize: KeySize, cipher: Algorithm)Encrypt the bound document.
EncryptFile(userPassword: string, ownerPassword: string, privilege: DocumentPrivilege, keySize: KeySize)Encrypt the bound document defaulting cipher to AES.
TryEncryptFile(userPassword: string, ownerPassword: string, privilege: DocumentPrivilege, keySize: KeySize)Try-variant of EncryptFile(string,string,DocumentPrivilege,KeySize,Algorithm).
SetPrivilege(privilege: DocumentPrivilege)Apply privilege flags to the bound document by re-encrypting with empty passwords and the given permissions.
SetPrivilege(userPassword: string, ownerPassword: string, privilege: DocumentPrivilege)Apply privilege flags with explicit passwords.
TrySetPrivilege(userPassword: string, ownerPassword: string, privilege: DocumentPrivilege)Try-variant of SetPrivilege(string,string,DocumentPrivilege).
DecryptFile(ownerPassword: string)Decrypt the bound document using the given password.
TryDecryptFile(ownerPassword: string)Try-variant of DecryptFile(string).
ChangePassword(ownerPassword: string, newUserPassword: string, newOwnerPassword: string)Change passwords on the bound document while preserving existing privileges and AES-128 encryption.
ChangePassword(ownerPassword: string, newUserPassword: string, newOwnerPassword: string, privilege: DocumentPrivilege, keySize: KeySize)Change passwords and override privileges + key size.
ChangePassword(ownerPassword: string, newUserPassword: string, newOwnerPassword: string, privilege: DocumentPrivilege, keySize: KeySize, cipher: Algorithm)Change passwords and override privileges + key size + cipher.
TryChangePassword(ownerPassword: string, newUserPassword: string, newOwnerPassword: string)Try-variant of ChangePassword(string,string,string).
TryChangePassword(ownerPassword: string, newUserPassword: string, newOwnerPassword: string, privilege: DocumentPrivilege, keySize: KeySize)Try-variant of the 5-arg ChangePassword(string,string,string,DocumentPrivilege,KeySize).
TryChangePassword(ownerPassword: string, newUserPassword: string, newOwnerPassword: string, privilege: DocumentPrivilege, keySize: KeySize, cipher: Algorithm)Try-variant of the 6-arg ChangePassword(string,string,string,DocumentPrivilege,KeySize,Algorithm).
EncryptFile(input: byte[], userPassword: string, ownerPassword: string, permissions: DocumentPrivilege?, algorithm: CryptoAlgorithm)Encrypt a PDF with the specified passwords and algorithm.
DecryptFile(input: byte[], password: string)Remove encryption from a PDF using the correct password.
ChangePasswords(input: byte[], oldOwnerPassword: string, newUserPassword: string, newOwnerPassword: string, algorithm: CryptoAlgorithm)Change the passwords on an encrypted PDF.

See Also