When I try to decrypt a file on my computer the file gets corrupted. Same code in Android Java works perfectly when encrypting and decrypting a file. I convert file to byte[], then encrypt and save it. Then load the saved file and decrypt it and save it again. The text encryption and decryption works fine and does not corrupt the file. Encrypting and decrypting file on PC does not corrupt it. sending PC encrypted file to Android does not corrupt when Android decrypts it. But when I send Android encrypted file and try to decrypt on PC it is corrupt.
EDIT:
Decryption code:
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] byteRaw = cipher.doFinal(encrypted);
return byteRaw;
I know using ECB is unsecure compared to CBC but i am doing it as demonstration that you can encrypt and decrypt files on android and PC
This is how i save the byte to file:
File file = new File("decrypted.jpg");
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bos.write(byteRaw);
bos.flush();
bos.close();
The code for encryption and decryption is exactly the same on android and PC, thus theoretically should work on both devices.