NodeJs encrypt message using authentication token

767 Views Asked by At

My goal is to encrypt end-to-end messaging app messages. I am wondering if it's possible to encrypt/decrypt messages using token authentication libraries such as jsonwebtoken? Is it a good approach or there are is dedicated library/algorithm for that?

Thank you mates in advance!

1

There are 1 best solutions below

2
On

No mate, JWT can't be used to encrypting/decryting messages. Because the data in the Jsonwebtoken can be read by any third party.

Real purpose of JWT in early days for using message can be something like ensuring message integrity. Means ​message is not tampered while sending and receiving.

If you want implement real end-to-end encryption(not even server read the message). You should implement like whatsapp. WhatsApp is using diffie Hellman Algorithm which is more secure way for end to end encryption. But it takes lot of work and implementation.

For simple implementation use symmetric encryption and decryption. Check this link below.

https://hackernoon.com/creating-real-time-chat-app-using-react-and-socketio-with-e2e-encryption-b0113u5s