—Information accurate as of: build 904.83
A Door Key costs 25 Wood per key to make. It allows the bearer of the key to open, close, lock and unlock the Door. Each time a Lock is deployed on a door, it is assigned, by the game, a number between one and 100, which keys made from it will acquire; unless a Door Key used on it matches that number, it will not unlock the door. To create a key, the door must be unlocked; the player goes up to their Key Lock and presses the "E" key (by default) on the lock. While any key and 25 Wood is held in inventory, a duplicate key for it can be created; pressing E on the door will not create a key if one already exists. The Lock can be removed while it is unlocked, and deploying it again will reset the number, probably rendering existing keys unusable.
Door keys must be carefully safeguarded so other players cannot gain access to your building via the door. You should make two keys for your main door. The first key is kept inside the base in a safe location. This allows for new copies of your key to be made if the second key is permanently lost or you wish to make a copy for a friend. The second key is placed in a Small Stash or Wood Storage Box in a bush, crevasse, or other hidden area outside your building. Once you return to your building, check that you haven't been followed and retrieve your Door Key for re-entry. Be sure to create a Sleeping Bag inside your building before attempting this strategy in the case the second key is misplaced or destroyed.
Redeploying your Lock and making a new key for it will regain control of your Lock should another player acquire one of your keys, or can be used to gain control of another player's Lock if you acquire one of their keys. Deploying a Lock multiple times, and making a key from it each time, increases the chance that the multiple keys in inventory will match other player's Locks, and is the basic principle behind Key Raiding.
Key Raiding is not simply making an inventory of 100 keys and having a 100% chance of opening any lock. There is a random chance that a key created is a duplicate of another already made. Even with a hypothetical, impossible inventory of 100 keys, a handful of them would be duplicates, and there would be no keys to match a handful of potential locks. With 69 keys you have a ~50% chance of having at least one matching key, and every time you double your number of keys you halve the chance of failure ( 0.99^[number of keys] = [chance none match] ).
Whether keys are truly random each craft isn't known for sure.