I have got this info from another forum.
ITseems To unlock an iPhone 3Gs you need the NCK which is a unique 15 digit key. Those keys for unlocking are sitting on Apples servers and send to the iPhone via iTunes while the iPhone is connected to the Mac/PC.
Each iPhone has a unique HWID, NORID, CHIPID, (id's embedded in the iphone hardware/chips and unique to each phone), the NCK is only working with the one iPhone where the above are matching. The NCK does not unlock any other iPhone. the official unlock is usually done this way.
Trying to bruteforce the NCK would take years even on high-end computers (NCK Brute Force - The iPhone Wiki).
Trying to guess the NCK is limited aswell, After 5 or so unsuccessful attemts, the iPhone becomes permanently locked to the carrier - unless you're feeling really, really lucky.
Apple has HWID, NORID, CHIPID... of all iPhones sold in countries, where the iPhone has to be sold unlocked (About activating iPhone 3G with a wireless carrier). So once a phone of those is connected via iTunes, the apple servers check HWID, NORID, CHIPID and compare it to their database. If the matching iPhone is marked "factory unlocked" the Apple servers send the unique NCK for this iPhone."
IF this is the case, why can't this unlock be just like any other computer application unlock which uses server authentication.. Like exchange server for example.
