Archived Forum Post

Index of archived forum posts

Question:

Skip Ahead in an Encrypted Stream and Continue Decrypting?

Jan 12 '15 at 21:05

I am creating a InputStream that decrypt file on the fly. Since the android media player always send range http request, my InputStream must be able to decrypt bytes between a range requested by the player. My code for that is at the end of the email. I used AES/CTR/NoPadding and IV size of 16 bytes.

I found that when I decrypt from beginning to end, everything works nicely. However when I skip on fileInputStream, it doesn’t work. In my test I have one encrypted file and its normal file. I compare output by my own InputStream with encrypted file and FileInputStream with normal file, they should be the same.


Answer

Block encryption algorithms can be used in different modes of operation (counter mode, cipher-block chaining, electronic cookbook, cipher feedback, etc.) Most of these modes are such that the encryption of the next block (16 bytes in many algorithms) uses the results of the previous block. Therefore, usually the only way to decrypt is to sequentially decrypt from beginning to end.

See the article here on Block Cipher Modes of Operation: http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation On the referenced web page, see the sample image (of the Linux penguin) and how the results look when encrypted with ECB mode.

With ECB mode, you can easily skip ahead, but only in increments of the algorithms block size (such as 16-byte blocks for AES). The same is true for CTR mode, except that you need a way to also advance the counter -- and this functionality is not yet available in Chilkat (at the time of this writing). I'll consider adding this feature (assuming I haven't misunderstood anything critical), for the next week or two (given the holidays).


Answer

Thanks very much, advancing counter would be great feature :)


Answer

Hi, just want to check if this feature is being implemented? Many thanks