An enrolment key is set in the Course Administration > Users > Enrolment methods > specific method that requires the key (for example, Self enrolment). This is only available to set for people with the correct privileges. The key can be as simple or as complex as you like.
Once someone has accessed a course with an enrolment key, they will retain access even if the key changes. So changing a key is not a way to purge old users. To do this you will need to reset your course. For more information see Managing people, roles and groups.