Java – Android AES issues

Android AES issues… here is a solution to the problem.

Android AES issues

I’m trying to encrypt/decrypt my files using AES. I followed this tutorial encrypts my data, but I modified the code slightly so that I can use the same key to encrypt many files.

In addition to encrypting my files, my AES key is saved using RSA(this page,saveKey() method.

I encrypted the files on my PC and tried to decrypt them on Android. However, I always come across BadPaddingException: pad block corrupted. I printed out the AES key and found that the decrypted AES key was different on PC and Android using the same private key.

If I decrypt the same file on my PC, it works fine.

Why?!

Is there a problem with Android’s password?!

Solution

Your RSA stuffing password may be using the wrong padding scheme

Try this?

pkCipher = Cipher.getInstance("RSA/NONE/PKCS1Padding");

Related Problems and Solutions