So, I've developed a user chat using Websockets, with ASP.MVC on the server.
I wanted to encrypt all messages (using AES) sent and received from websockets. To do so, I tried to encrypt the user message before sending (using Crypto.js) and decrpyt it on the server (using Security.Cryptography .net).
The problem is that the encrypted message on the client is different from the encrypted message on the server (with message,key and initialization vector being the same on the client and the user).
Is this a good way of doing the websockets message encrypting? What other solutions would you recommend me?
CryptoJS:
var encrypted = CryptoJS.AES.encrypt("Message", communicationKey, { iv : communicationIV}, { mode: CryptoJS.mode.CFB }); .NET Cryptography:
byte[] encryptedMessage = EncryptStringToBytes_Aes(decryptedMessage, keyToDecrypt, ivToDecrypt); return Convert.ToBase64String(encryptedMessage); The Crypto.js encrypted string is:
U2FsdGVkX18wnoGfYzHo2Ms/6CKsRC+cE1fj8ylSPlI= And the .NET`s Security.Cryptography is:
kLApirWt1VcVu3tTuAizgA== I`m using the same key and initalization vector on both sides. What could be the problem?