First of all, to ensure a secure connection between your client application and the server, conceptually speaking, you only need the public key of the server. This allows you to establish a one-way trust with the server and establish a secure session in which server authentication is guaranteed.
Although the above method does not provide two-way trust (the client cannot be identified on the server), when establishing the communication channel in most applications, this level of trust is not required.
If your requirements are to ensure that the client is authenticated on the server using public / private keys, then everything becomes more complicated, because if you put the key in apk, no matter how confusing it is (including embedding it in your own library ) it will only slow down the work of a loyal vile user.
The only way to save the private key with the client is to encrypt it. But then you have a similar problem with where to store the decryption key. The simplest solution is to create a public / private key pair for the client application user and ask the user to provide a symmetric encryption / decryption key (which the user will always have to enter) to decrypt the private key each time the user uses the application.
An alternative would be to use some specialized cryptographic hardware device, like a smart card, which stores the secret key securely, but you still have the problem of authorizing your application to read the key from the device (not to mention the complication of interacting with the specified device).
Now the question that you should ask yourself is: "Who are you trying to not read the secret key?" (of course, after answering another question: "You really need a public / private key pair for the client").
Mike dinescu
source share