I have application working between server and client. All messages must be encrypted and decrypted. I use AES algorithm and I want method to hide the key.

I found Diffie-Hellman algorithm, but my problem is that I didn't find its source code. If the is another method for key exchange, please tell me.

  • 5
    three letters: TLS – SEJPM Dec 27 '15 at 20:57
  • Is there a reason why you are looking to implement this on your own versus using an existing solution? – Neil Smithline Dec 28 '15 at 0:13

This is exactly what SSL/TLS are supposed to do. SSL/TLS uses asymmetric encryption just in the handshake to exchange the symmetric key that is used from that moment on to encrypt the communication. The key exchanged is called a masterkey and is only used for that session. The lifetime of a session can be configured.

The process is basically this when you use HTTPS, for example:

  • Client establishes connection (three-way-handshake -> TCP handshake, after this the SSL/TLS handshake starts)
  • Server sends certificate (which includes the public key)
  • Client sends masterkey encrypted with the servers public key
  • Masterkey is used for that session

This is of course just a broad description of the protocol and only applies when the client itself has no certificate which is the case in most scenarios.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.