Open achhayapathak opened 3 months ago
I’ll take this one @achhayapathak
Sure @yashkathe
Did you work on this @yashkathe or shall I pick this up?
Did you work on this @yashkathe or shall I pick this up?
I'll take this one
The problem with adding encryption is that most algorithms require a special key, so how can we handle that? Or is there any encryption algorithm library that you can recommend?
This one will be a challenging problem to work on. One way to resolve this is to:
You can use libraries like crypto or bcrypt and any encryption algorithm like AES, RSA or blowfish to achieve this. My suggestion will be to go with AES-256 encryption with CBC mode. I have the code for encrypt and decrypt functions also for this one so if you want I can share that with you but you will get to learn a lot about encryption if you figure that out yourself.
I will try to research a bit but nevertheless, still share the code you wrote so I can have a look
const crypto = require('crypto');
// Generate a secure random key and initialization vector (IV) const key = crypto.randomBytes(32); // 32 bytes for AES-256 encryption const iv = crypto.randomBytes(16); // 16 bytes for AES initialization vector
// Function to encrypt a message function encrypt(text) { let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key), iv); let encrypted = cipher.update(text); encrypted = Buffer.concat([encrypted, cipher.final()]); return encrypted.toString('hex'); }
// Function to decrypt a message function decrypt(encryptedText) { let decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(key), iv); let decrypted = decipher.update(Buffer.from(encryptedText, 'hex')); decrypted = Buffer.concat([decrypted, decipher.final()]); return decrypted.toString(); }
This one is for the server side. For the client side, the functions will remain the same just the key and iv won't be generated but accepted by the user through a prompt.
Thank you for sharing the code, I'll have a look
are you working on this @yashkathe ?
I'm a bit busy currently. I will take a look when I am free. If its a bit urgent you can start with the development.
Encrypt the messages the enhance security.