In working on a piece of intranet software, I needed to implement security between the client and the server. I would like to know whether this is a secure way to do this or if there are significant holes.

The client and server come up with a shared secret using ECDH (secp521r1) key exchange. A new shared secret is negotiated for every request.

The encryption key is generated using Password-Based Key Derivation Function 2 (PBKDF2). I use the shared secret as the password, a preshared key as the salt (to only allow authorized clients to connect), 100,000 iterations, and the hash function is SHA512.

After that the request data is encrypted with aes-128-gcm, using the encryption key and an IV of 12 zeros. The response is encrypted using the same key. The server then discards the key so it cannot be used twice.

Is this a good implementation? Are there other better ways to do this? Is there something I am missing?

  • 4
    Why not just use SSL/TLS? What is special about your situation?
    – John Wu
    Commented Aug 4, 2017 at 2:29
  • Websockets don't seem to play well with self-signed certs, and in this case, I am encrypting messages between two server on the same network, so I don't really need SSL if another way also works. Commented Aug 4, 2017 at 11:06
  • 3
    If you think websockets don't play well with self signed certs then just wait to build this proposal! If you don't know how to setup your own CA maybe you shouldn't be jumping in at the deep end building your encryption stack.
    – symcbean
    Commented Oct 3, 2017 at 12:56
  • Why do you need to use self signed certs, rather than Lets Encrypt or similar?
    – jrtapsell
    Commented Jan 1, 2018 at 19:59

2 Answers 2


Do not roll your own cryptography

There have been multiple attacks on SSL/TLS which have been developed by the wider industry and been through scrutiny and testing. Don't build your own, stand on the shoulders of giants.

If this is an intranet project check to see if you have an internal CA and get an issued certificate from this. Don't use self signed certificates as well your weakening your own security by doing so. Anyone can issue them and then man-in-the-middle your traffic.

Also why is the IV unchanged? An IV should be regenerated each time its used.


From your question it appears that you already doing mutual authentication. that is a secure way to establish a mutual trust between a client and the server. please note that this is just a connection trusts, you still need to do application authentication, firewall rules, RBAC (role base access control) and IDM (identity management) in addition to your mutual auth.

  • The preshared key should establish that the client is at least authorized to connect, right? Commented Aug 7, 2017 at 1:44
  • preshared keys if you have a symmetric keys . do it with asymmetric keys. Basically :you create the key pairs for each end. then the client encrypts with the server public key and decrypts with it private key . and the server encryps with the client public key and decryps with its private key.
    – Hugo R
    Commented Aug 7, 2017 at 5:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .