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.
|
boolean |
getAllowExceptions()
Deprecated.
This property is deprecated and can not be used to allow throwing exceptions.
|
RuntimeException |
getLastException()
Returns exception which was thrown by last operation.
|
void |
setAllowExceptions(boolean value)
Deprecated.
This property is deprecated and can not be used to allow throwing exceptions.
|
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.
|
boolean |
tryChangePassword(String ownerPassword,
String newUserPassword,
String newOwnerPassword)
Changes the user password and owner password by owner password, keeps the original security settings.
|
boolean |
tryChangePassword(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 |
tryChangePassword(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 document security.
|
boolean |
tryDecryptFile(String ownerPassword)
Decrypts an encrypted Pdf document by owner password.
|
boolean |
tryEncryptFile(String userPassword,
String ownerPassword,
DocumentPrivilege privilege,
int keySize)
Encrypts Pdf file with userpassword and ownerpassword and sets the document's privileges to access.
|
boolean |
trySetPrivilege(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 object@Deprecated public final boolean getAllowExceptions()
If this value set to true, exception will be thrown on operation failure. Else, method returns false on failure and last exception can be checked with LastException property.
@Deprecated public final void setAllowExceptions(boolean value)
If this value set to true, exception will be thrown on operation failure. Else, method returns false on failure and last exception can be checked with LastException property.
value
- boolean valuepublic final RuntimeException getLastException()
Returns exception which was thrown by last operation.
public 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. Throws exception if process failed.
String inFile = "input.pdf"; // The TestPath may be // re-assigned. String outFile = "output.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 final boolean tryEncryptFile(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. Does not throw an exception if process failed.
string inFile = "input.pdf"; //The TestPath may be re-assigned. string outFile = "output.pdf"; //The TestPath may be re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile,outFile); bool result = fileSecurity.tryEncryptFile("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. Throws an exception if process failed.
String inFile = "input.pdf"; // The TestPath may be // re-assigned. String outFile = "output.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 final 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. Throws an exception if process failed.
string inFile = "input.pdf"; //The TestPath may be re-assigned. string outFile = "output.pdf"; //The TestPath may be re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile,outFile); fileSecurity.decryptFile("ownerpass");
ownerPassword
- Owner password.public final boolean tryDecryptFile(String ownerPassword)
Decrypts an encrypted Pdf document by owner password. If the document hasn't owner password, it is allow to use user password. Does not throw an exception if process failed.
string inFile = "input.pdf"; //The TestPath may be re-assigned. string outFile = "output.pdf"; //The TestPath may be re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile,outFile); bool result = fileSecurity.TryDecryptFile("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. Throws an exception if process failed.
string inFile = "input.pdf"; // The TestPath may be re-assigned. string outFile = "output.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. Throws an exception if process failed.
string inFile = "input.pdf"; // The TestPath may be re-assigned. string outFile = "output.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 final boolean trySetPrivilege(String userPassword, String ownerPassword, DocumentPrivilege privilege)
Sets Pdf file security with original password. Does not throw an exception if process failed.
string inFile = "D:\\input.pdf"; //The TestPath may be re-assigned. string outFile = "D:\\output.pdf"; //The TestPath may be re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile,outFile); bool result = fileSecurity.trySetPrivilege(userPassword, ownerPassword, DocumentPrivilege.Print);
userPassword
- Original user password.ownerPassword
- Original owner password.privilege
- Set privilege.public final 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. Throws an exception if process failed.
string inFile = "D:\\input.pdf"; //The TestPath may be re-assigned. string outFile = "D:\\output.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 final boolean tryChangePassword(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 Does not throw an exception if process failed. with a random string if the new owner password is null or empty.
string inFile = "D:\\input.pdf"; //The TestPath may be re-assigned. string outFile = "D:\\output.pdf"; //The TestPath may be re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile,outFile); bool result = fileSecurity.tryChangePassword("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. Throws an exception if process failed.
string inFile = "input.pdf"; // The TestPath may be // re-assigned. string outFile = "output.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 final boolean tryChangePassword(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. Does not throw an exception if process failed.
string inFile = ".D:\\input.pdf"; //The TestPath may be re-assigned. string outFile = "D:\\output.pdf"; //The TestPath may be re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile,outFile); bool result = fileSecurity.tryChangePassword("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. Throws an exception if process failed.
string inFile = "input.pdf"; // The TestPath may be // re-assigned. string outFile = "output.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 final boolean tryChangePassword(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 document 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. Does not throw an exception if process failed.
string inFile = "D:\\input.pdf"; //The TestPath may be re-assigned. string outFile = "D:\\output.pdf"; //The TestPath may be re-assigned. PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile,outFile); bool result = 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.