public final class PdfFileSecurity extends Object
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)
Initializes new
PdfFileSecurity object on base of the
document . |
PdfFileSecurity(IDocument document,
String outputFile)
Initializes new
PdfFileSecurity object on base of the
document . |
PdfFileSecurity(InputStream inputStream,
OutputStream outputStream)
Initialize the object of PdfFileSecurity with input and output stream.
|
PdfFileSecurity(String inputFile,
String outputFile)
Initializes the object of PdfFileSecurity with input and output file.
|
Modifier and Type | Method and Description |
---|---|
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() |
boolean |
decryptFile(String ownerPassword)
Decrypts an encrypted Pdf document by owner password.
|
void |
dispose() |
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.
|
IDocument |
getDocument()
Gets the document
PdfFileSecurity is working on. |
void |
setInputFile(String value)
Sets the input file.
|
void |
setInputStream(InputStream value)
Sets the input stream.
|
void |
setOutputFile(String value)
Sets the output file.
|
void |
setOutputStream(OutputStream value)
Sets the output stream.
|
boolean |
setPrivilege(DocumentPrivilege privilege)
Sets Pdf file security without being encrypted.
|
boolean |
setPrivilege(String userPassword,
String ownerPassword,
DocumentPrivilege privilege)
Sets Pdf file security with original password.
|
public PdfFileSecurity(InputStream inputStream, OutputStream outputStream)
Initialize the object of PdfFileSecurity with input and output stream.
inputStream
- Input Pdf Stream.outputStream
- Output Pdf Stream.public PdfFileSecurity(String inputFile, String outputFile)
Initializes the object of PdfFileSecurity with input and output file.
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.public PdfFileSecurity(IDocument document, String outputFile)
Initializes new PdfFileSecurity
object on base of the
document
.
document
- Pdf document.outputFile
- Output Pdf file.public PdfFileSecurity(IDocument document, OutputStream outputStream)
Initializes new PdfFileSecurity
object on base of the
document
.
document
- Pdf document.outputStream
- Output Pdf Stream.public void setInputFile(String value)
Sets the input file.
public void setInputStream(InputStream value)
Sets the input stream.
public void setOutputFile(String value)
Sets the output file.
public void setOutputStream(OutputStream value)
Sets the output stream.
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.
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 without being encrypted. 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.Print);
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 IDocument getDocument()
Gets the document PdfFileSecurity
is working on.
public void close()
public void dispose()
Copyright © 2020 Aspose. All Rights Reserved.