For a client / server application, the best way to ensure security is to use TLS / SSL.
The latest version of TLS is TLS 1.2 ( RFC 5246 ), and as WagnerVaz rightly mentioned, the best open source library available for TLS is a href = "http://www.openssl.org/" rel = "nofollow" > OpenSSL. OpenSSL not only provides a library for TLS / Crypto. But it also provides you with a tool for creating certificates and private keys (based on RSA / DSA, etc.) in various formats.
Although OpenSSL is the best TLS library available on the market, it is a little difficult to understand and use for the first timer. There is a very wonderful tutorial written by Eric Rescorla himself on using OpenSSL.
Introduction to OpenSSL Programming (Part I) / Introduction to OpenSSL Programming (Part II)
It would be better if you first tried to understand what SSL is, and then start writing code for it.
As an alternative, suppose you are only interested in asymmetric encryption / decryption, but the OpenSSL Crypto libraries can be used.
source share