I think doors should have combinations. Not necessarily keypads, just basically a number sequence you can assign to the door (perhaps either tap E to open door, or hold E for context menu - one of the options is “Change Key”). When you craft a key, again you specify a combination for it.
So keys can only open doors if they match the combination. That way, when a friend dies, he/she can tell you to go through and change all of the combinations so the key won’t work on the door.
Or perhaps instead, you physically craft a lock with metal fragments, and perhaps just like Research Kits maybe there’s Key Kits. Drag a Key Kit onto a lock to craft a key if you have enough metal fragments. The keys crafted from the lock could basically be bound to that specific lock. Then you drop the lock onto your door, and all the keys you craft from that lock will open that lock (and only that lock). If keys become compromised, you have to physically craft new locks and new keys for your base and find some way to dispose of the old ones (as long as you replace ALL locks, you could just drop all the old locks and keys out the window for some lucky passerby)
EDIT: You should also be able to open your own doors even without a key - this is mainly so that friends can have a way into your base.