I am not a PHP encoder, so I need a little help with PHP AES encryption.
I write code where I encrypt image files in PHP and then decrypt them in Java (Android). Everything works fine when I encrypt / decrypt PNG files, but when I try to do the same with JPG, Java decryption throws an exception:
WARN/System.err(345): java.io.IOException: data not block size aligned
Based on an Internet search, it seems that this is due to the fact that I am filling out the content incorrectly.
How can I do it right?
Here is the PHP code for encryption:
<?php $secret_key = "01234567890abcde"; $iv = "fedcba9876543210"; $infile = "5.png"; $outfile = "5_encrypted.png"; $crypttext = file_get_contents($infile); $plaintext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $secret_key, $crypttext, MCRYPT_MODE_CBC, $iv); header('Content-Type: application/octet-stream'); header('Content-Length: ' . strlen($plaintext)); header('Content-Disposition: attachment; filename=' . ($outfile)); echo $plaintext;
source share