SetEncryption() public method

public SetEncryption ( X509Certificate certs, int permissions, int encryptionType ) : void
certs Org.BouncyCastle.X509.X509Certificate
permissions int
encryptionType int
return void
Esempio n. 1
0
        /** Entry point to encrypt a PDF document. The encryption parameters are the same as in
         * <code>PdfWriter</code>. The userPassword and the
         *  ownerPassword can be null or have zero length. In this case the ownerPassword
         *  is replaced by a random string. The open permissions for the document can be
         *  AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
         *  AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
         *  The permissions can be combined by ORing them.
         * @param reader the read PDF
         * @param os the output destination
         * @param userPassword the user password. Can be null or empty
         * @param ownerPassword the owner password. Can be null or empty
         * @param permissions the user permissions
         * @param strength128Bits <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length
         * @param newInfo an optional <CODE>String</CODE> map to add or change
         * the info dictionary. Entries with <CODE>null</CODE>
         * values delete the key in the original info dictionary
         * @throws DocumentException on error
         * @throws IOException on error
         */
        public static void Encrypt(PdfReader reader, Stream os, byte[] userPassword, byte[] ownerPassword, int permissions, bool strength128Bits, Hashtable newInfo)
        {
            PdfStamper stamper = new PdfStamper(reader, os);

            stamper.SetEncryption(userPassword, ownerPassword, permissions, strength128Bits);
            stamper.MoreInfo = newInfo;
            stamper.Close();
        }
        /** Entry point to encrypt a PDF document. The encryption parameters are the same as in
         * <code>PdfWriter</code>. The userPassword and the
         *  ownerPassword can be null or have zero length. In this case the ownerPassword
         *  is replaced by a random string. The open permissions for the document can be
         *  AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
         *  AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
         *  The permissions can be combined by ORing them.
         * @param reader the read PDF
         * @param os the output destination
         * @param strength <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length
         * @param userPassword the user password. Can be null or empty
         * @param ownerPassword the owner password. Can be null or empty
         * @param permissions the user permissions
         * @param newInfo an optional <CODE>String</CODE> map to add or change
         * the info dictionary. Entries with <CODE>null</CODE>
         * values delete the key in the original info dictionary
         * @throws DocumentException on error
         * @throws IOException on error
         */
        public static void Encrypt(PdfReader reader, Stream os, bool strength, String userPassword, String ownerPassword, int permissions, Dictionary <string, string> newInfo)
        {
            PdfStamper stamper = new PdfStamper(reader, os);

            stamper.SetEncryption(strength, userPassword, ownerPassword, permissions);
            stamper.MoreInfo = newInfo;
            stamper.Close();
        }
Esempio n. 3
0
        /** Entry point to encrypt a PDF document. The encryption parameters are the same as in
         * <code>PdfWriter</code>. The userPassword and the
         *  ownerPassword can be null or have zero length. In this case the ownerPassword
         *  is replaced by a random string. The open permissions for the document can be
         *  AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
         *  AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
         *  The permissions can be combined by ORing them.
         * @param reader the read PDF
         * @param os the output destination
         * @param type the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.
         * Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext
         * @param userPassword the user password. Can be null or empty
         * @param ownerPassword the owner password. Can be null or empty
         * @param permissions the user permissions
         * @param newInfo an optional <CODE>String</CODE> map to add or change
         * the info dictionary. Entries with <CODE>null</CODE>
         * values delete the key in the original info dictionary
         * @throws DocumentException on error
         * @throws IOException on error
         */
        public static void Encrypt(PdfReader reader, Stream os, int type, String userPassword, String ownerPassword, int permissions, Hashtable newInfo)
        {
            PdfStamper stamper = new PdfStamper(reader, os);

            stamper.SetEncryption(type, userPassword, ownerPassword, permissions);
            stamper.MoreInfo = newInfo;
            stamper.Close();
        }
 public void Encrypt(PdfStamper stamper)
 {
     int permission = 0;
     foreach (int i in this.Permissions)
     {
         permission |= (int) i;
     }
     stamper.SetEncryption(this.Encryption, this.UserPwd, this.OwnerPwd, permission);
 }
Esempio n. 5
0
// ---------------------------------------------------------------------------
    /**
     * Manipulates a PDF file src with the file dest as result
     * @param src the original PDF
     */
    public byte[] EncryptPdf(byte[] src) {
      PdfReader reader = new PdfReader(src);
      using (MemoryStream ms = new MemoryStream()) {
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
          stamper.SetEncryption(
            USER, OWNER, 
            PdfWriter.ALLOW_PRINTING, 
            PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA
          );
        }
        return ms.ToArray();
      }
    }    
Esempio n. 6
0
 /** Entry point to encrypt a PDF document. The encryption parameters are the same as in
  * <code>PdfWriter</code>. The userPassword and the
  *  ownerPassword can be null or have zero length. In this case the ownerPassword
  *  is replaced by a random string. The open permissions for the document can be
  *  AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
  *  AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
  *  The permissions can be combined by ORing them.
  * @param reader the read PDF
  * @param os the output destination
  * @param userPassword the user password. Can be null or empty
  * @param ownerPassword the owner password. Can be null or empty
  * @param permissions the user permissions
  * @param strength128Bits <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length
  * @param newInfo an optional <CODE>String</CODE> map to add or change
  * the info dictionary. Entries with <CODE>null</CODE>
  * values delete the key in the original info dictionary
  * @throws DocumentException on error
  * @throws IOException on error
  */
 public static void Encrypt(PdfReader reader, Stream os, byte[] userPassword, byte[] ownerPassword, int permissions, bool strength128Bits, Dictionary<string,string> newInfo) {
     PdfStamper stamper = new PdfStamper(reader, os);
     stamper.SetEncryption(userPassword, ownerPassword, permissions, strength128Bits);
     stamper.MoreInfo = newInfo;
     stamper.Close();
 }
Esempio n. 7
0
 /** Entry point to encrypt a PDF document. The encryption parameters are the same as in
  * <code>PdfWriter</code>. The userPassword and the
  *  ownerPassword can be null or have zero length. In this case the ownerPassword
  *  is replaced by a random string. The open permissions for the document can be
  *  AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
  *  AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
  *  The permissions can be combined by ORing them.
  * @param reader the read PDF
  * @param os the output destination
  * @param type the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.
  * Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext
  * @param userPassword the user password. Can be null or empty
  * @param ownerPassword the owner password. Can be null or empty
  * @param permissions the user permissions
  * values delete the key in the original info dictionary
  * @throws DocumentException on error
  * @throws IOException on error
  */
 public static void Encrypt(PdfReader reader, Stream os, int type, String userPassword, String ownerPassword, int permissions) {
     PdfStamper stamper = new PdfStamper(reader, os);
     stamper.SetEncryption(type, userPassword, ownerPassword, permissions);
     stamper.Close();
 }
Esempio n. 8
0
 /** Entry point to encrypt a PDF document. The encryption parameters are the same as in
  * <code>PdfWriter</code>. The userPassword and the
  *  ownerPassword can be null or have zero length. In this case the ownerPassword
  *  is replaced by a random string. The open permissions for the document can be
  *  AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
  *  AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
  *  The permissions can be combined by ORing them.
  * @param reader the read PDF
  * @param os the output destination
  * @param type the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.
  * Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext
  * @param userPassword the user password. Can be null or empty
  * @param ownerPassword the owner password. Can be null or empty
  * @param permissions the user permissions
  * @param newInfo an optional <CODE>String</CODE> map to add or change
  * the info dictionary. Entries with <CODE>null</CODE>
  * values delete the key in the original info dictionary
  * @throws DocumentException on error
  * @throws IOException on error
  */
 public static void Encrypt(PdfReader reader, Stream os, int type, String userPassword, String ownerPassword, int permissions, Dictionary<string,string> newInfo) {
     PdfStamper stamper = new PdfStamper(reader, os);
     stamper.SetEncryption(type, userPassword, ownerPassword, permissions);
     stamper.MoreInfo = newInfo;
     stamper.Close();
 }
Esempio n. 9
0
 /** Entry point to encrypt a PDF document. The encryption parameters are the same as in
  * <code>PdfWriter</code>. The userPassword and the
  *  ownerPassword can be null or have zero length. In this case the ownerPassword
  *  is replaced by a random string. The open permissions for the document can be
  *  AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
  *  AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
  *  The permissions can be combined by ORing them.
  * @param reader the read PDF
  * @param os the output destination
  * @param strength <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length
  * @param userPassword the user password. Can be null or empty
  * @param ownerPassword the owner password. Can be null or empty
  * @param permissions the user permissions
  * @param newInfo an optional <CODE>String</CODE> map to add or change
  * the info dictionary. Entries with <CODE>null</CODE>
  * values delete the key in the original info dictionary
  * @throws DocumentException on error
  * @throws IOException on error
  */
 public static void Encrypt(PdfReader reader, Stream os, bool strength, String userPassword, String ownerPassword, int permissions, Hashtable newInfo) {
     PdfStamper stamper = new PdfStamper(reader, os);
     stamper.SetEncryption(strength, userPassword, ownerPassword, permissions);
     stamper.MoreInfo = newInfo;
     stamper.Close();
 }