I run into folk all the time with this question. It's usually locked to the carrier and only they will release it. Sometimes you have to pay off their bill or such.
Here it's often cheaper to buy the unlocked phone, even if used.
That's the safe way. There are too many rip offs out there.
I have Samsung Galaxy SIII mini, locked to a Canada carrier. I want to unlock and use it in Canada. How can I get a code safely?