I’m very glad that you didn’t wait to write to us. At only 12, your mind is very flexible and open to change. Good for you for understanding that your response to others is not usual and that there is help for it.
What you are describing may be a form of tactile defensiveness. Tactile defensiveness is a sensory processing disorder where the individual has a negative reaction to one or more types of sensations (such as touch). In your case, it seems to be selective. You are okay with touch by people you feel safe with but not by strangers. That’s not entirely a bad thing. The problem seems to be that you don’t have control of your reactions. It’s as if you have only two options — ok with people you are close to; not ok with others. Most people have a range of types of touch they allow from different kinds of people.
There are strategies for becoming more comfortable with touch. The internet has some good articles about it. If trying out some of the recommended techniques isn’t helpful enough, do think about seeing a therapist who can help you gradually gain more control of the issue.
I wish you well.