I'm creating a huge, online mobile game. I have a few questions for you guys because my knowledge in cryptography and sending data across the network securely is kinda poor.
Some details:
- Each user has an account
- To log in you have to provide your username and password (through the app, not the web browser)
- The data is transferred from the client (mobile device) to the server somewhere.
Simple! Ok so as I know, normal web authentication is secured by SSL which is just "send plain, you're safe".
On mobile I can't use SSL (even if Android provides some methods, I just can't cause I'm porting my game to iOS, using different game/networking engines etc).
I have to make the "sending & receiving" process secure so a 3rd person won't catch user's credentials.
As I read, the best way to perform this is the RSA method which uses public and private keys to encrypt/decrypt packets.
From my knowledge it works like:
- there are two keys, private, public and a message: "message".
- anyone can get a public key (because it's public)
- only the server has the access to the private key
- anyone can encrypt the "message" with the public key and it will always look the same (same msg encrypted with same public key)
- the encrypted message can be decrypted in only one way - using a private key and it will look like the first message: "message".
- public and private keys are not equal but they use different encrypt/decrypt algorithms so it works magically that at the end the message is the same
Please, correct me if I'm wrong!
And here are my questions:
- Am I right in the above example, that packets sent this way (and with public key being really public) are secured (of course anything can be decrypted) but, you know, is it "secure"?
- Should each user have its own pair of keys?
- When should I generate a new pair of keys? With each login?
- When should I send a public key to the user? When he clicks 'register' or 'login' (with already filled textfields with the data)? Or when he opens the app?
If there is someone that could explain these things a little bit I would be grateful! :)
Two additional questions to @Luke Park
Public key is public and you said that it shouldn't be sent over the network. Does it mean that with a public key user can decrypt the data somehow?
And the second: You said that I should bundle the public key with the application. If the public key is also a dangerous tool in a hacker's hands, is it wise to store it in code? As I know there are ways to retrieve the data from the compiled program.
And one extra! If the key is bundled (probably hardcoded) - should it always stay the same or should I ever change the pair (generate new)? As I read somewhere, by having a public key 'public' it's possible to crack the data (it takes some time, but it's possible).