I want to encrypt messages before sending them on websocket.
Connect to a secure websocket (wss:
- the WebSocket equivalent of https:
), and this happens automatically, so you don't need to do any encryption or decryption yourself.
If you do want to write cryptography code in JavaScript for any other reason though, you have the full browser built-in Web Crypto API at your disposal.