Encryption in minifilter

I have searched to list for several days trying to find information about a typical problem that is asked a lot but I have not found a solution.

I have the typical encryption driver based on minifilter. I decrypt in PostRead and encrypt in PreWrite (swapping buffers as in the IFS example). I just encrypt/decrypt the reads and writes which will go to/from cache (those with IrpFlags & (IRP_NOCACHE | IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO).

The driver is mostly working but I have some problems with .JPG files. I show them in a Explorer advanced view as thumbnails. Then I open one of them for edition (with mspaint) and add something (for example a red rectangle). When I save the file, the thumbnail is not updated. If I use the right-button option of “Update thumbnail” it is updated but after I reboot the machine, the .JPG is corrupted (neither the thumbnail nor the file itself can be viewed).

What am I missing?

Thanks in adavance.