Answer:
Take the key code to the locksmith (not a hardware) and they should have a replacement key for you.
You can also order replacement locks I found homakkeys.com they seem to carry some gun safe locks. At least for the cheaper thin walled safes. I am considering buying a set from them as I noticed my key was missing after getting my tires replaced. It may have been missing before but for peace of mind I would rather drill (about 30 minutes) and replace my lock. Knowing that my guns are still secure. Rather than wondering if some questionable mechanic who may have my key but insists he doesn't has access to my safe.
http://homakkeys.com/Keyinformation.html
I think the question asked is how to replace the LOCK not the key. I've recently had the electronic lock on my gun safe become inoperable. Fortunately for me, my safe was open when I realized the keypad was no longer responsive.
If you don't know the manufacturer of your keypad, call the safe maker and find out. The electronic keypad (which is the most common point of failure) can be replaced easily at home. Find a replacement part on the internet (make sure it's compatible with your safe). You'll save hundreds. BTW upgrade to a Sergeant and Greenleaf keypad, they cost a bit more but are much more reliable than the no namers out there.