It does not have to go through the SWD in clear. Don't forget please, that SWD does not program FLASH memory directly, it is only a R/W interface for generic RAM and register area with some command on top (run/halt CPU, etc).
Usually you first put a FLASH loader algorithm program in the SRAM, feed it a chunk of data to be written and then you run the program from the SRAM, that will program the FLASH memory. I can easily imagine you could implement some cryptography in there.
The large advantage of doing so is that you can write arbitrary flash loaders even for external memory devices, which comes very handy.