So my app downloads videos from the internet but encrypts it on-the-fly while downloading it and writes the encrypted data to the storage. I am using AES/CTR/NoPadding. How can I append encrypted data to already encrypted file? That's because the download may stop or the connection may go down so the app can resume the download. I tried this by passing append parameter on a resume situation, the file gets completed (resumed) and I can decrypt the file back (no problem) but the file is corrupted and when I compare it to an encrypted file which was downloaded at one shot (no pause and resume) it is totally different. Also the file which is downloaded at one shot is fully working after decryption, its playable and all the bits are intact.
I am using a hardcoded 128bit key and a hardcoded 128bit IV.
You can use the same scheme to set the offset for decryption, which I've laid out in this answer. Actually, for CTR mode, encryption is the same operation as decryption, so it is obvious that both operations work in identical ways. Of course you will have to store the IV with the ciphertext in advance for this to work.