I wrote a script for FreeBSD 11 to safely rename such files to be named by their own SHA1 hash sum plus their original extension. (Files with bad characters in extension are made extension-less.)
Here is the script: https://github.com/eriknstr/utils/blob/master/shaname.sh
I have commented the script in detail so that readers may quickly see what's going on and which assumptions are made, so that they may determine whether the script is appropriate for their use-case.
I reiterate that the script was written for FreeBSD 11 and should not be used on platforms with commands that have incompatible arguments.
The script is released under the ISC license.
Pull requests are welcome.