If you need to transfer messages from the application to the application, then use JWT, if you want to encrypt all traffic between machines, and ensure the integrity and authenticity of the data, then use an encryption system with public and private keys.
I suggest using JWT
Json Web Token. This is an open standard RFC 7519 for filing (claims) between two participants.
It is a structure of the form: Header.Payload.Signature, where the header and payload are packed hashes in base64 json. Here it is worth paying attention to payload. It can contain anything, in principle, it can be just a client_id and some other information about the user, but this is not a good idea, it’s better to transfer only the key identifier, and store the data somewhere else .
Here are a few notes to help improve security when using JWT:
When creating a token, you must enter the user's IP address into his body. Then, with each request, verify this field with the address where the request came from. Thus, even with a token, the attacker will not be able to use it. This method imposes some additional inconvenience for the user, for example, you will have to log in again every time his IP changes. However, in most cases this does not happen very often and should not cause much discomfort.
You can, of course, with each request, pull your database and check the data from the token with the data in the user's record. In other words, with each request to access the database, get the user and make sure that the request can be executed, while what and how to check depends only on your idea. It is possible to check if the user is blocked, if he has changed the password since the issuance of the token, if his role is appropriate, etc. This method is rather rough, but as efficient as possible. However, there is a more practical and interesting way to check that does not force your main database - see item 3.
Storing a list of current tokens (the so-called “white list”) in a separate high-performance database, such as Redis or Memcahed. With each request, after a normal check of the token for validity, we also check its presence in this database. If for some reason it was not there - then the request cannot be executed and you need to get a new token. Thus, after some critical actions with the account (change of password, change of role, ban, etc.), we simply remove from the white list all tokens related to this account.