Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC:

PDF AES stream 9 years 9 months ago #6649

  • petr.sklenicka
  • petr.sklenicka's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 36
  • Thank you received: 0
Hello,
I have a problem with using of a class PDFAESStream. I have an encrypted book and I'm trying to open it. For this purpose I use this code:
PDFAESStream stream = new PDFAESStream();
stream.open(bookPath, "MySecretKeyABCDE".getBytes());

The bookPath variable is an existing path to the book, which is encrypted via AES.
The open() method always returns false. For encryption, I simply used AES/CBC/PKCS5Padding. The open() method still returns false, because the condition
if( m_enc_len % BLOCK_ENC_SIZE != 4 ) // Line from your code

is always true.

Where is the problem?
Thank you in advance for your reply.

Please Log in or Create an account to join the conversation.

PDF AES stream 9 years 9 months ago #6652

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
PDFAESStream is customer format file.
you shall use PDFAESStream.ImportFromFile() to create a encrypted PDF file.

to create encrypted PDF file codes like:
PDFAESStream stream = new PDFAESStream();
stream.ImportFromFile( "path-name" );
stream.ExportToFile( "an other path-name" );
stream.close();

to open encrypted PDF file codes like:
PDFAESStream stream = new PDFAESStream();
stream.open( "path_name", password );
Document doc = new Document();
doc.OpenStream( stream, ... );
doc.Close();
stream.close();

PDFAESStream may used in pure java envirment on linux/windows and so on.

Please Log in or Create an account to join the conversation.

PDF AES stream 9 years 9 months ago #6655

  • petr.sklenicka
  • petr.sklenicka's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 36
  • Thank you received: 0
Ok, thank you for your reply.

I tried your code, but it does not work. A method ImportFromFile returns false. The problem is with this line:
m_file.setLength(0);

m_file is null. I use exactly this code:
PDFAESStream stream = new PDFAESStream();
stream.ImportFromFile(inputPath);
stream.ExportToFile(outputPath);
stream.close();

The variable inputPath is path of the book and this path exists.

Please Log in or Create an account to join the conversation.

PDF AES stream 9 years 9 months ago #6658

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
sorry, forgot something.
codes:
PDFAESStream stream = new PDFAESStream();
stream.open( outputPath, password );
stream.ImportFromFile(inputPath);
stream.close();

Please Log in or Create an account to join the conversation.

PDF AES stream 9 years 9 months ago #6660

  • petr.sklenicka
  • petr.sklenicka's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 36
  • Thank you received: 0
This code works. It creates a new file with length 4096 bytes. Is this correct? I thought that it will create a new file - the encrypted PDF document with AES.

Please Log in or Create an account to join the conversation.

PDF AES stream 9 years 9 months ago #6663

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
there are example in ReaderActivity.java
some codes are commented.
//byte key[] = new byte[16];
//stream.open("/sdcard/ttt.pdf", key);
//stream.ImportFromFile("/sdcard/test.pdf"); //encrypt to /sdcard/ttt.pdf
//stream.ExportToFile("/sdcard/test1.pdf"); //decrypt to /sdcard/test1.pdf

these codes shall tested.

Please Log in or Create an account to join the conversation.

Last edit: by .
  • Page:
  • 1
  • 2
Powered by Kunena Forum