It isn't supported.

There are two alternatives if you use 2.0:

1) use keylength 256 => AES256 will be used
or
2) change the source code. In  StandardSecurityHandler.java there is a line

//TODO return 4 if keyLength is 128 to enable AES128 functionality

replace it with this:

else if (keyLength == 128)
    return 4;

and your files can be encrypted with AES128 if you use keylen 128.

There is no "official" way to enable AES128 encryption with a setter. The AES128 encryption/decryption was implemented very recently by me (as part of an issue that dealt with signing encrypted documents - PDFBOX-2729), I didn't want to make too much changes before the 2.0 release because it wouldn't have been tested enough.

Tilman

Am 18.02.2016 um 13:56 schrieb M. Niedermair:
Hello,

I have a problem with the AES encryption algorithm.

The PDF generated still displays RC4 and opening only blank pages are displayed. I use iText with AES, AES is displayed and when opening all the pages are displayed correctly.
What am I doing wrong?

greeting
Michael

My Code:
import java.io.File;
import java.io.IOException;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
import org.apache.pdfbox.pdmodel.encryption.PDEncryption;
import org.apache.pdfbox.pdmodel.encryption.SecurityHandler;
import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy;
import org.apache.pdfbox.util.Version;

public class Test01 {

   public static void main(final String[] args) throws IOException {
      final File input = new File("s10.pdf");
      final File output = new File("target/s10-secure.pdf");

      final AccessPermission ap = new AccessPermission();
      ap.setCanPrint(true);
      ap.setCanPrintDegraded(true);
      ap.setCanModify(false);
      ap.setCanAssembleDocument(false);
      ap.setCanExtractContent(false);
      ap.setCanFillInForm(false);
      ap.setCanExtractForAccessibility(false);
      ap.setCanModifyAnnotations(false);

      PDDocument document = PDDocument.load(input);

final StandardProtectionPolicy spp = new StandardProtectionPolicy("12345", null, ap);
      spp.setEncryptionKeyLength(128);
      document.protect(spp);
      document.getEncryption().getSecurityHandler().setAES(true);
document.getEncryption().getSecurityHandler().setKeyLength(128);
      document.setVersion(1.5f);
      document.save(output);
      document.close();
      System.out.println(output.getName() + " create");

      // relaod and print info...
      document = PDDocument.load(output);
      printInfo(document);
      document.close();

      // load pdf create with itext
      System.out.println("\n-------- with iText ----------------------");
      document = PDDocument.load(new File("s10-itext.pdf"));
      printInfo(document);
      document.close();

   }

private static void printInfo(final PDDocument document) throws IOException {
      System.out.println("pdfbox     : " + Version.getVersion());
      System.out.println("Version    : " + document.getVersion());
      System.out.println("encrypted  : " + document.isEncrypted());

final AccessPermission perm = document.getCurrentAccessPermission(); System.out.println("enc_accesspermission : " + perm.canAssembleDocument()); System.out.println("enc_extractcontent : " + perm.canExtractContent()); System.out.println("enc_extractforaccessibility : " + perm.canExtractForAccessibility()); System.out.println("enc_fillinform : " + perm.canFillInForm()); System.out.println("enc_modify : " + perm.canModify()); System.out.println("enc_modifyannotations : " + perm.canModifyAnnotations()); System.out.println("enc_print : " + perm.canPrint()); System.out.println("enc_printdegraded : " + perm.canPrintDegraded());

      final PDEncryption enc = document.getEncryption();
      System.out.println("enc_length      : " + enc.getLength());
      final SecurityHandler sh = enc.getSecurityHandler();
      System.out.println("enc_sh_length   : " + sh.getKeyLength());
System.out.println("enc_sh_name : " + (sh.isAES() ? "AES" : "RC4"));
   }

}

Output:
s10-secure.pdf create
pdfbox     : 2.0.0-RC3
Version    : 1.5
encrypted  : true
enc_accesspermission        : false
enc_extractcontent          : false
enc_extractforaccessibility : false
enc_fillinform              : false
enc_modify                  : false
enc_modifyannotations       : false
enc_print                   : true
enc_printdegraded           : true
enc_length      : 128
enc_sh_length   : 40
enc_sh_name     : RC4

-------- with iText ----------------------
pdfbox     : 2.0.0-RC3
Version    : 1.5
encrypted  : true
enc_accesspermission        : false
enc_extractcontent          : false
enc_extractforaccessibility : false
enc_fillinform              : false
enc_modify                  : false
enc_modifyannotations       : false
enc_print                   : true
enc_printdegraded           : true
enc_length      : 128
enc_sh_length   : 40
enc_sh_name     : AES


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to