It is not so difficult, you just need to authenticate the application. You can do this with a simple user and password (via SSL) or use client authentication. In both cases, the credentials must be in the application, and an attacker can extract them and impersonate the application. You should go away with him and perhaps implement some methods to mitigate it.
You can also authenticate messages by signing them with an asymmetric key (RSA, etc.) or symmetric (HMAC, etc.). The nonce function helps against retries when someone captures correctly signed messages and sends them to your server again and again. Depending on your protocol, the overhead of using one may be too much.
To protect the credentials, you can force them to generate them and save them in the KeyStore system, although this is not entirely supported by the public API, see here for some details. This, of course, requires an additional step in which you need to securely send the generated credentials (for example, a public key) to your server, which can be difficult to implement correctly.
Whatever you do, do not try to invent your own cryptographic algorithm or protocol, use the installed one.
source share