- Posts: 7
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
PDFAESStream for AES256 decoding returning -3
9 years 9 months ago #10668
by AppStudio
PDFAESStream for AES256 decoding returning -3 was created by AppStudio
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
trying to open the stream.
To open the pdf, we use:
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!
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
trying to open the stream.To open the pdf, we use:
Code:
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!
9 years 9 months ago #10669
by support
Replied by support on topic PDFAESStream for AES256 decoding returning -3
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.
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.
9 years 9 months ago #10670
by support
Replied by support on topic PDFAESStream for AES256 decoding returning -3
Sorry, better read your request.
It you're reading your file from an encrypted streaming, isn't?
We should better investigate about your request.
It you're reading your file from an encrypted streaming, isn't?
We should better investigate about your request.
9 years 9 months ago #10672
by support
Replied by support on topic PDFAESStream for AES256 decoding returning -3
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.
I should check whether we could support you here or move you to the reserved trouble ticket area.
9 years 9 months ago - 9 years 9 months ago #10674
by AppStudio
Replied by AppStudio on topic PDFAESStream for AES256 decoding returning -3
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):
-edit-
The PDF itself does not have a password; the whole document itself is encrypted using the above php code.
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):
Code:
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.
Last edit: 9 years 9 months ago by AppStudio.
9 years 9 months ago #10676
by radaee
Replied by radaee on topic PDFAESStream for AES256 decoding returning -3
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.
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.
Time to create page: 0.422 seconds