0

I have a server, and a client. To encrypt the data, I want to use AES-128. Someone told me to use different salt for every message. My problem is the following: if I generate a random salt at the client side, send the message, how can I decrypt it on the other side? The server has no idea about the salt.

P.S. I'm writing the code in C#, and I use tcp socket communication.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
  • 6
    Salt value (initialization vector, actually) is not a secret. It is sent in clear along with the encrypted test. – Remus Rusanu Sep 30 '18 at 08:44
  • Should I send the message like: 16 bit salt + encrypted message? In this way the server read the first 16 bit, and decrypt the rest of data with the salt. If the salt is so public, how should it defend me against rainbow table attacks? –  Sep 30 '18 at 09:11
  • This question has nothing todo with sockets. It essentially only asks how to properly encrypt and decrypt with AES. There is no need to use a different salt to derive the encryption key from the password for each message - but you should of course use a random IV for each message. – Steffen Ullrich Sep 30 '18 at 09:18
  • 4
    Possible duplicate of [Passphrase, Salt and IV, do I need all of these?](https://stackoverflow.com/questions/1905112/passphrase-salt-and-iv-do-i-need-all-of-these) or [Symmetric Encryption (AES): Is saving the IV and Salt alongside the encrypted data safe and proper?](https://stackoverflow.com/questions/13901529/symmetric-encryption-aes-is-saving-the-iv-and-salt-alongside-the-encrypted-da). – Steffen Ullrich Sep 30 '18 at 09:22
  • 1
    For dat in transit best is to use some off the shelf protocol, like TLS/SSL. C# offers an implementation out-of-the-box like [`SslStream`](https://learn.microsoft.com/en-us/dotnet/api/system.net.security.sslstream?view=netframework-4.7.2). There are many things to consider, like replays, man-in-the-middle, HMACs and so on. Don't implement your own. – Remus Rusanu Sep 30 '18 at 10:04
  • 2
    @randomguy With AES CBC mode the random salt is used for the IV and is 16 **bytes**, not bits. – zaph Sep 30 '18 at 13:51

0 Answers0