[Galaxy S 4 Mini Q&A, Help & Troubleshooting] Morthawt:
Edit:

Check this whole first post, because I have made some additional entries concerning failures and potential cures to things. I will update when my current encryption test is complete.

For the short version see the tldr at the bottom.

I have been trying different combinations of things all day in my last ditch attempt to get encryption working without needing to flash my original firmware back on from odin, since I hate the thought of how long it takes and what could go wrong.

The secret that I have worked out today is I install TWRP, wipe everything out, factory reset, wipe etc. Then install the rom, in my case it was my TWRP backup of my original firmware installed and then later CM11 M12, then immediately after flashing, reboot to download mode and flash the stock recovery image (I had to get a guide and use my linux VPS to turn the extracted recovery.img into a .tar.md5 and use that for flashing my original recovery. Then boot to recovery (now the genuine original recovery) and perform a factory reset. Then boot the phone up and the encryption works. Right now CM11 is at 38% encryption! Just before I started this off, I also had 100% success with encryption using my TWRP backup of a stock firmware install, using this same method. Once it is encrypted I will flash TWRP back on here as I did before and it should be good.

My theory (I am too burned out to test it at this point, I just want my phone working...) is that the issue is not whether you have TWRP installed, but whether the final factory reset (before booting up phone for usage) is performed by an official recovery or a third party recovery. So I bet it would work if you perform the factory reset and then immediately flash TWRP back on there and then boot up and perform the encryption.

Plus, in theory since I am using CM11 encryption, TWRP should be able to access /data which means I can keep this encryption and flash what ever rom I want using TWRP and upon booting it "should" just work. I tested this once before when I lucked out and got encryption working on some rom (I forget now which it was) but I was able to do a wipe with TWRP and install a different rom and the encryption still worked, still booted up fine.

Do you have any thoughts on this topic? Maybe I am reinventing the wheel...? I have not seen any of this referenced in any of the text or video guides I have been checking out. So I thought I would share this just in case. It might work for other samsung phones too.

STAND BY. The encryption did not work and I am trying a slight modification that is also proceeding. I am 19% on encrypting CM10.2. This time I did the usual TWRP wipes and then once wiped, Immediate flash of the original stock recovery (no OS install yet), then perform a factory reset and then flash TWRP again. Then I installed CM10.2 and skipped through the setup wizard and went straight to setting up encryption. Where usually it fails, it is actually performing the encryption. I have hopes that since the factory reset from the stock firmware's recovery was performed BEFORE the OS install, that it should... should work this time. I have a feeling the prior one failed because of doing a factory reset from one rom's recovery on a different rom's OS. So doing the factory reset before the OS install might be what will make it work. I will update soon.

Edit: It worked flawlessly... Booted up, authenticated, everything is fine. I am now running the same test with CM11 (M12) Also, I am not sure if this will work, but once I performed the final factory reset via the stock recovery (before re-flashing TWRP to begin OS install) I made a backup. My hope is that instead of reflashing and re-flashing back and forth, that the backup I made will have everything ready as if I had done a stock recovery based factory reset. If I decide to ditch CM11 I will test this theory out. I should also mention that the last test I mentioned with CM10.2 worked even though TWRP was presently still installed. So the presence of the stock recovery is not required, rather it is the factory reset from a stock rom being the final step required before the OS ROM install process.

Edit: There seems to be an issue with CM11. Twice now it has failed to work on CM11. I will try CM12 next, using my backup of a freshly official factory reset. If it fails I will do the whole process on 12 and see if it works and report back.

Edit: CM12 encryption by using the TWRP backup of a freshly factory reset (via stock recovery) failed. I am in the process of waiting for the first initial boot and setup wizard to complete of my second attempt at CM12 encryption via the full final step of actual stock recovery factory reset before CM12 installation via TWRP that is flashed after the stock recovery factory reset. I will update if this works. If it works and boots up correctly while encrypted, then it means a TWRP of a stock recovery factory reset is not adequate to replicate a true factory reset and the developers of TWRP should be made aware of this so they can enhance their own factory reset feature to allow encryption to work. If it doesn't work then there is something definitely wrong with CM11 and CM12 since both the stock firmware and CM10.2 encrypt using this full factory reset method. Stay tuned, wizard just came on screen...

Edit: Ok, weird... this time the encryption process has begun, whereas using my TWRP backup that was made after doing the stock factory reset did not get to this point, although the percentage counter started from 100% and counting... Right now the encryption is at 146% completed. That is very odd... I will report back if the encryption process actually ends up with a successfully booting phone or not, since CM11 failed at the booting phase. Before I save this edit, ne thing I am noticing is the progress percentage is going up rather fast compared to any other ROM. Right now it is at 177% and right now it is 179%, now it is 183% and I type fast... Stay tuned.

Edit: The encryption process worked and rebooted, asked for authentication and came up, however upon unlocking verious apps like CM bug reporter and whisper and others crash sometimes resulting in a OS loading screen and a fresh unlock needing to be performed.

tldr: When installing ANY rom, you need to wipe the file systems with TWRP or other similar recovery, then flash your stock firmware's recovery image (not the whole firmware, just the recovery, which means you need to extract the recovery.img from your flash file using 7zip and then follow these instructions: http://www.w0lfdroid.com/2013/04/android-how-to-convert-img-recovery-to.html to create a .tar.md5 file that odin can use to flash your recovery rom. (load odin, click AP or PDA and set your recovery tar.md5 and untick the two boxes that are always on by default. I use Odin v3.09). Then after you have wiped the file systems with TWRP (format data, then wipe the other mount points) then with your stock recovery perform a factory reset. Then flash TWRP or what ever custom recovery you use and just install your ROM, no other formatting or anything else, just install (not restore). Then the encryption will work, assuming there are no bugs in the rom that prevent it working on your handset, as seen on my handset with CM11 and the weird bugs with apps crashing on CM12.

So my recommendation is that the developer(s) of TWRP change the way they perform the factory reset, to emulate the actual process that a stock recovery uses, so that you do not need to keep reflashing your recovery images over and over when you need a fresh install.

Notes: CM11 M12 fails to boot, post successful encryption process, while CM12 nightly (18th March 2015) has bugs with apps crashing after successful bootup post encryption.