The knowledge itself is not illegal.
But in your example it is illegal to accquire the key in that manner. The owner of the key is not giving it to you with his knowledge and agreement. It would be like telling someone: "Hey, this is your front door, unlock it with your key" and he would put his key into the lock and you would theoretically be able to copy the key when the user put it into your faked front door's lock.
If you'd try that out with your key and you being fully aware that your key is being copied and consent to it, it is not illegal. But to just create a copy without someone knowing it is most likely illegal. Same with cracking/bruteforcing the key. Even if you don't use it, just attemping to is illegal. In which way you accquire the key without the consent of the user, you commit something illegal.