public final class PdfFileSecurity extends SaveableFacade implements com.aspose.ms.System.IDisposable
Represents encrypting or decrypting a Pdf file with owner or user password, changing the security setting and password.
Constructor and Description |
---|
PdfFileSecurity()
Initialize the object of PdfFileSecurity.
|
PdfFileSecurity(IDocument document)
Initializes new
PdfFileSecurity object on base of the document . |
PdfFileSecurity(IDocument document,
OutputStream outputStream)
Deprecated.
|
PdfFileSecurity(IDocument document,
String outputFile)
Deprecated.
|
PdfFileSecurity(InputStream inputStream,
OutputStream outputStream)
Deprecated.
|
PdfFileSecurity(String inputFile,
String outputFile)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
bindPdf(InputStream srcStream)
Initializes the facade.
|
void |
bindPdf(String srcFile)
Initializes the facade.
|
boolean |
changePassword(String ownerPassword,
String newUserPassword,
String newOwnerPassword)
Changes the user password and owner password by owner password, keeps the original security
settings.
|
boolean |
changePassword(String ownerPassword,
String newUserPassword,
String newOwnerPassword,
DocumentPrivilege privilege,
int keySize)
Changes the user password and password by owner password, allows to reset Pdf documnent
security.
|
boolean |
changePassword(String ownerPassword,
String newUserPassword,
String newOwnerPassword,
DocumentPrivilege privilege,
int keySize,
int cipher)
Changes the user password and password by owner password, allows to reset Pdf documnent
security.
|
void |
close()
Closes the facade.
|
boolean |
decryptFile(String ownerPassword)
Decrypts an encrypted Pdf document by owner password.
|
void |
dispose()
Closes the facade.
|
boolean |
encryptFile(String userPassword,
String ownerPassword,
DocumentPrivilege privilege,
int keySize)
Encrypts Pdf file with userpassword and ownerpassword and sets the document's privileges to
access.
|
boolean |
encryptFile(String userPassword,
String ownerPassword,
DocumentPrivilege privilege,
int keySize,
int cipher)
Encrypts Pdf file with userpassword and ownerpassword and sets the document's privileges to
access.
|
void |
setInputFile(String value)
Deprecated.
|
void |
setInputStream(InputStream value)
Deprecated.
|
void |
setOutputFile(String value)
Deprecated.
|
void |
setOutputStream(OutputStream value)
Deprecated.
|
boolean |
setPrivilege(DocumentPrivilege privilege)
Sets Pdf file security with empty user/owner passwords.
|
boolean |
setPrivilege(String userPassword,
String ownerPassword,
DocumentPrivilege privilege)
Sets Pdf file security with original password.
|
save, save
bindPdf, bindPdf, bindPdf, getDocument
@Deprecated public PdfFileSecurity(InputStream inputStream, OutputStream outputStream)
Initialize the object of PdfFileSecurity with input and output stream.
Obsolete("Use constructor without destination.")
inputStream
- Input Pdf Stream.outputStream
- Output Pdf Stream.@Deprecated public PdfFileSecurity(String inputFile, String outputFile)
Initializes the object of PdfFileSecurity with input and output file.
Obsolete("Use constructor without destination.")
inputFile
- Source input Pdf file.outputFile
- Output Pdf file.public PdfFileSecurity()
Initialize the object of PdfFileSecurity.
public PdfFileSecurity(IDocument document)
Initializes new PdfFileSecurity
object on base of the document
.
document
- Pdf document.@Deprecated public PdfFileSecurity(IDocument document, String outputFile)
Initializes new PdfFileSecurity
object on base of the document
.
Obsolete("Use constructor without destination.")
document
- Pdf document.outputFile
- Output Pdf file.@Deprecated public PdfFileSecurity(IDocument document, OutputStream outputStream)
Initializes new PdfFileSecurity
object on base of the document
.
Obsolete("Use constructor without destination.")
document
- Pdf document.outputStream
- Output Pdf Stream.@Deprecated public void setInputFile(String value)
Sets the input file.
Obsolete("Use bindPdf(inputStream) method for facade initialization.")value
- String object@Deprecated public void setInputStream(InputStream value)
Sets the input stream.
Obsolete("Use bindPdf(inputStream) method for facade initialization.")value
- InputStream object@Deprecated public void setOutputFile(String value)
Sets the output file.
Obsolete("Use save(outputStream) method for getting facade results.")value
- String object@Deprecated public void setOutputStream(OutputStream value)
Sets the output stream.
Obsolete("Use save(outputStream) method for getting facade results.")value
- OutputStream objectpublic boolean encryptFile(String userPassword, String ownerPassword, DocumentPrivilege privilege, int keySize)
Encrypts Pdf file with userpassword and ownerpassword and sets the document's privileges to access. The user password and the owner password can be null or empty. The owner password will be replaced with a random string if the input owner password is null or empty.
String inFile = "..\\AsposePdfKitExample\\example1.pdf"; // The TestPath may be // re-assigned. String outFile = "..\\AsposePdfKitExample\\Kit0401.pdf"; // The TestPath may be // re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile); fileSecurity.EncryptFile("userpass", "ownerpass", DocumentPrivilege.Print, KeySize.x256);
userPassword
- User password.ownerPassword
- Owner password.privilege
- Set privilege.keySize
- KeySize.x40 for 40 bits encryption, KeySize.x128 for 128 bits encryption and KeySize.x256 for
256 bits encryption.public boolean encryptFile(String userPassword, String ownerPassword, DocumentPrivilege privilege, int keySize, int cipher)
Encrypts Pdf file with userpassword and ownerpassword and sets the document's privileges to access. The user password and the owner password can be null or empty. The owner password will be replaced with a random string if the input owner password is null or empty. There are 6 possible combinations of KeySize and Algorithm values. However (KeySize.x40, Algorithm.AES) and (KeySize.x256, Algorithm.RC4) are invalid and corresponding exception will be raised if kit encounters this combination.
String inFile = "..\\AsposePdfKitExample\\example1.pdf"; // The TestPath may be // re-assigned. String outFile = "..\\AsposePdfKitExample\\Kit0401.pdf"; // The TestPath may be // re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile); fileSecurity.encryptFile("userpass", "ownerpass", DocumentPrivilege.Print, KeySize.x256, Algorithm.AES);
userPassword
- User password.ownerPassword
- Owner password.privilege
- Set privilege.keySize
- KeySize.x40 for 40 bits encryption, KeySize.x128 for 128 bits encryption and KeySize.x256 for
256 bits encryption.cipher
- Algorithm.AES to encrypt using AES algorithm or Algorithm.RC4 for RC4 encryption.public boolean decryptFile(String ownerPassword)
Decrypts an encrypted Pdf document by owner password. If the document hasn't owner password, it is allow to use user password.
string inFile = "..\\AsposePdfKitExample\\Kit0401.pdf"; // The TestPath may be // re-assigned. string outFile = "..\\AsposePdfKitExample\\Kit0404.pdf"; // The TestPath may be // re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile); fileSecurity.DecryptFile("ownerpass");
ownerPassword
- Owner password.public boolean setPrivilege(DocumentPrivilege privilege)
Sets Pdf file security with empty user/owner passwords. The owner password will be added by a random string.
string inFile = "..\\AsposePdfKitExample\\example1.pdf"; // The TestPath may be re-assigned. string outFile = "..\\AsposePdfKitExample\\Kit0405.pdf"; // The TestPath may be re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile); fileSecurity.setPrivilege(DocumentPrivilege.Print);
privilege
- Set privilege.public boolean setPrivilege(String userPassword, String ownerPassword, DocumentPrivilege privilege)
Sets Pdf file security with original password.
string inFile = "..\\AsposePdfKitExample\\example1.pdf"; // The TestPath may be re-assigned. string outFile = "..\\AsposePdfKitExample\\Kit0405.pdf"; // The TestPath may be re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile); fileSecurity.setPrivilege(userPassword, ownerPassword, DocumentPrivilege.getPrint());
userPassword
- Original user password.ownerPassword
- Original owner password.privilege
- Set privilege.public boolean changePassword(String ownerPassword, String newUserPassword, String newOwnerPassword)
Changes the user password and owner password by owner password, keeps the original security settings. The new user password and the new owner password can be null or empty. The owner password will be replaced with a random string if the new owner password is null or empty.
string inFile = "..\\AsposePdfKitExample\\Kit0406.pdf"; // The TestPath may be // re-assigned. string outFile = "..\\AsposePdfKitExample\\Kit0407.pdf"; // The TestPath may be // re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile); fileSecurity.ChangePassword("owner", "newuser", "newowner");
ownerPassword
- Original Owner password.newUserPassword
- New User password.newOwnerPassword
- New Owner password.public boolean changePassword(String ownerPassword, String newUserPassword, String newOwnerPassword, DocumentPrivilege privilege, int keySize)
Changes the user password and password by owner password, allows to reset Pdf documnent security. The new user password and the new owner password can be null or empty. The owner password will be replaced with a random string if the new owner password is null or empty.
string inFile = "..\\AsposePdfKitExample\\Kit0401.pdf"; // The TestPath may be // re-assigned. string outFile = "..\\AsposePdfKitExample\\Kit0407.pdf"; // The TestPath may be // re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile); fileSecurity.ChangePassword("owner", "newuser", "newowner", DocumentPrivilege.Print, KeySize.x256);
ownerPassword
- Original owner password.newUserPassword
- New User password.newOwnerPassword
- New Owner password.privilege
- Reset security.keySize
- KeySize.x40 for 40 bits encryption, KeySize.x128 for 128 bits encryption and KeySize.x256 for
256 bits encryption.public boolean changePassword(String ownerPassword, String newUserPassword, String newOwnerPassword, DocumentPrivilege privilege, int keySize, int cipher)
Changes the user password and password by owner password, allows to reset Pdf documnent security. The new user password and the new owner password can be null or empty. The owner password will be replaced with a random string if the new owner password is null or empty. There are 6 possible combinations of KeySize and Algorithm values. However (KeySize.x40, Algorithm.AES) and (KeySize.x256, Algorithm.RC4) are invalid and corresponding exception will be raised if kit encounters this combination.
string inFile = "..\\AsposePdfKitExample\\Kit0401.pdf"; // The TestPath may be // re-assigned. string outFile = "..\\AsposePdfKitExample\\Kit0407.pdf"; // The TestPath may be // re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile); fileSecurity.ChangePassword("owner", "newuser", "newowner", DocumentPrivilege.Print, KeySize.x256, Algorithm.AES);
ownerPassword
- Original owner password.newUserPassword
- New User password.newOwnerPassword
- New Owner password.privilege
- Reset security.keySize
- KeySize.x40 for 40 bits encryption, KeySize.x128 for 128 bits encryption and KeySize.x256 for
256 bits encryption.cipher
- Algorithm.AES to encrypt using AES algorithm or Algorithm.RC4 for RC4 encryption.public void bindPdf(String srcFile)
Initializes the facade.
public void bindPdf(InputStream srcStream)
Initializes the facade.
public void close()
Closes the facade.