My votes go to @Naftuli Kay, and other helpful answer here, but I have some info I'd like to share. It's too long for a comment, let it be an answer then.
Since some version of TWRP, there's 'format data' item on Wipe screen. It not only wipes /data partition, but also handles the encrypted FS matter. In my case, TWRP 3.0.2 on Samsung J500H wipes encryption, and it was the only way, factory reset doesn't work. CMR (that one being built along my CM 12.1 rom for J500H) can't clear encryption either.
--set_encrypted_filesystem=off also didn't work in TWRP and CMR.
wiping data via OpenRecoveryScript https://twrp.me/faq/openrecoveryscript.html also doesn't work
Android 3.0 started to map /sdcard to /data/media, so they had to rework /data wipe to not /data/media, and
rm -rf is performed instead. See https://twrp.me/faq/datamedia.html for more details.
When you perform 'format data' you may see in recovery log (/cache/recover/log or /cache/recovery/last_log) following info:
I:Successfully wiped crypto footer.
before it formats /data with
make_ext4fs. The TWRP code has number of checks to find where the LUKS header is, and in my case it found it in the footer.
I looked at the TWRP source and I haven't found a way to 'format data' from command line (I need to wipe encrypted storage from an application in custom rom), so this option is present in UI only. With the only exception - if TWRP is compiled with
TW_OEM_BUILD enabled then it will 'format data' on factory reset, clearing crypto header and formatting data partition, otherwise it would use regular wipe w/o formatting.
I'm going to try to
dd with zeros, actually TWRP does the same to clear encryption, just it knows where to look for the header exactly ))