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

TOPIC:

PDFAESStream for AES256 decoding returning -3 7 years 10 months ago #10668

  • AppStudio
  • AppStudio's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 7
  • Thank you received: 0
We have a problem using PDFAESStream to decode a pdf.
We do have certain requirements, so after it didn't work the first time, we changed things a bit. But we still get a int ret =-3 trying to open the stream.

To open the pdf, we use:
PDFAESStream stream = new PDFAESStream();
            stream.open(m_filePathString, GetData.getInstance().getKeyBytes(), GetData.getInstance().getIVBytes());
            m_doc = new Document();
            int ret = m_doc.OpenStream(stream, null); //no password on the pdf itself
            mPDFReader.PDFOpen(m_doc,false,this);

We use php to encode our files ("openssl enc -e -aes-256-cbc") using a 32byte key and a random 16byte IV.
The file decodes correctly using our custom iOS solution;. the pdf file is valid and readable/displayable.
I have changed the signiture of PDFAESStream.open( String path, byte[] key) to PDFAESStream.open( String path, byte[] key , byte[] ivb) because we do use a random iv for every file (this is needed for encryption safety: PDFAESStream SHOULD use this too instead of using a fixed IV!).
As our keybytes are a byte[32], I have also changed:
static private int BLOCK_DEC_SIZE = BLOCK_ENC_SIZE-32; //this was -16

But the pdf file still will not open. Could this have anything to do with the static private int BLOCK_ENC_SIZE = 4096;? Or maybe the many "-4"'s found the rest of the code?

Please help us decode our pdf without having to pre-decode it ourselves to disc! Thanks!

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

PDFAESStream for AES256 decoding returning -3 7 years 10 months ago #10669

  • support
  • support's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 692
  • Thank you received: 59
May you provide one of your pdf document?
Are your PDF compliant to PDF1.7 level 6? AES256 encryption has been restored on that format as in previous the implementation was bugged and insecure: only AES128 was officially supported.

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

PDFAESStream for AES256 decoding returning -3 7 years 10 months ago #10670

  • support
  • support's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 692
  • Thank you received: 59
Sorry, better read your request.

It you're reading your file from an encrypted streaming, isn't?
We should better investigate about your request.

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

PDFAESStream for AES256 decoding returning -3 7 years 10 months ago #10672

  • support
  • support's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 692
  • Thank you received: 59
May you provide your modified PDFAESStream class and a valid url to retrive an encrypted file?
I should check whether we could support you here or move you to the reserved trouble ticket area.

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

PDFAESStream for AES256 decoding returning -3 7 years 10 months ago #10674

  • AppStudio
  • AppStudio's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 7
  • Thank you received: 0
I've attached the java file ... it's just the PDFAESStream with the above changes.
The pdf we've encrypted is downloaded into our app's getApplicationInfo().dataDir. We're trying to stream it into our implementation of the Radaee reader from there so we do not have to copy a decrypted version of it on the system during runtime.

The function we use to encrypt the pdf is this one (php):
public static function file($data, $username, $password, $deviceid){
                               if(crypt::$key===false){
                                               crypt::$key = hash_pbkdf2('sha256',$username.$password.$deviceid,SALT,50000,32,true);
                               }
                               return openssl_encrypt($data, 'AES-256-CBC', crypt::$key, OPENSSL_RAW_DATA, IV);
                }

-edit-
The PDF itself does not have a password; the whole document itself is encrypted using the above php code.
Attachments:

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

Last edit: by AppStudio.

PDFAESStream for AES256 decoding returning -3 7 years 10 months ago #10676

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
thanks, it better explaned this issue.
PDFAESStream defined inner structs, not encrypt a file as whole data object.
PDFAESStream split a file to many blocks, each is 4096 - padding bytes.
and, this Stream class can be run as normal java program on any platform.
u'd better using PDFAESStream to encrypt PDF files.

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

  • Page:
  • 1
  • 2
Powered by Kunena Forum