Remove illegal characters from keys