2

I'm trying to decrypt a file received from my REST API. I've encrypted the file with openssl on linux with the command line

openssl aes-256-cbc -k mypassword -in file_test.pdf -out file_crypted.pdf

I've tried almost all possibilities with android and it always end up with an error, nothing works well.

This is my last code version

String password = "mypassword";
byte[] srcString = FileUtils.readFileToByteArray(new File("my_file.pdf"));
SecretKeySpec key = new SecretKeySpec(password.getBytes(), "AES");
Cipher aesCBC = Cipher.getInstance("AES/CBC/PKCS5Padding");
aesCBC.init(Cipher.DECRYPT_MODE, key);
byte[] decrypted = aesCBC.doFinal(srcString);

Do you have any idea how could I fix this

jww
  • 97,681
  • 90
  • 411
  • 885
  • Usually [`EVP_BytesToKey`](http://wiki.openssl.org/index.php/Manual:EVP_BytesToKey(3)) is one of the issues. See [Java equivalent of C++ encryption](http://stackoverflow.com/q/12920740/608639), [How to use OpenSSL generated keys in Java?](http://security.stackexchange.com/q/9600/29925), [Java openssl encryption / decryption key generation](http://stackoverflow.com/q/34502705/608639), [Password to key function compatible with OpenSSL commands?](http://stackoverflow.com/q/9488919), [How to decrypt file in Java encrypted with openssl command using AES?](http://stackoverflow.com/q/11783062), etc. – jww Oct 09 '17 at 21:07
  • Please place answers in Answer blocks. Don't add them to the question. That's the way Stack overflow works. Also see [Can I answer my own question?](https://stackoverflow.com/help/self-answer) in the Help Center. – jww Oct 10 '17 at 22:09

0 Answers0