Say I have a mobile messaging app. There is a central server that manages stuff (like a directory of users, onboarding, etc.) and there are all the clients.
My app is professional, so it uses asymmetric encryption to securely send messages.
My question is, in short, should the client or the server generate the public-private key pair?
If the client generates the pair, then the pair can be generated on the client-side and then sent to the server (maybe encrypted with the server's public key).
If the server generates the pair, then I had a more complicated idea:
- Client generates secret (
- Client encrypts secret with server's public key
- Client sends encrypted secret to server
- Server decrypts encrypted secret with server's private key
- Server generates public-private key pair for client
- Server encrypts private key with secret (
S) and removes it from memory
- Server sends encrypted private key to server
- Client decrypts encrypted private key with secret (
S), which it had from the beginning
- Hooray! Client now has private key and public key is on server!!! :)
So, which approach is better--should the client or the server generate the public-private key pair from a security perspective? Is there a better/more efficient/more secure way to do it than my solutions?