I have a hobby electronics project in mind for an electronic key (think house key, car key. etc., i.e., physical key). It would be a PCB that would be inserted into a slot. Both the key and lock would have dedicated hardware, yet to be determined. I'm thinking about using something like public key encryption, with the public key being stored in the hardware in the key (call this the client) and the private key being stored in the lock (server). While this is just a hobby project and I understand that nothing can be 100% secure, the public key will need to be transmitted to the server from the client to lock or unlock the lock. This poses a problem. If the public key is transmitted, it can be intercepted. If it can be intercepted, then the key can easily be copied, rendering the encryption useless.
How can this be mitigated? I was thinking about the server sending a code of some sort, possibly based on a hardware-based random number generator, to the client that would be used to obfuscate the public key. Still, that doesn't solve the problem; the contents of the key are not an issue. If the obfuscated key is intercepted, then we are back at square one. I feel like I am part way to the solution with this, but am missing a key portion.
I'm getting the feeling that what I am after is simply impossible. I know that quantum-based encryption is supposed to address this, but I am not going there, even if I could.