Dave
Dave

Reputation: 2900

Is possible to encode WebSocket messages?

Is possible to encode or obfuscate or something else, what Im sending via websockets? Example message:

var msg = {
    type: "message",
    data: {
        message: "Hello world!"
    }
}

I need to send this message as unreadable and at server-side I need decode it back to readable version. I want block it from chrome console Netword tab (WS).

Upvotes: 1

Views: 1561

Answers (1)

yeya
yeya

Reputation: 2204

The data is generated on the user side, so you can't really hide the data from him.

But you can encode it anyway you want before sending just to hide it in the chrome console like this:

var msg = {
type: "message",
data: {
    message: btoa("Hello world!")
}

At the server side you just need to:

atob(message);

Also look here

Keep in mind: A motivated user can grab the data before the encoding happens, or even later and just make atob() by himself. there is not a 100% way to block it, it's the client data.

If you want to make his life harder, you can try to use crypto libraries with RSA, but again, he can capture it before the crypto begins.

Upvotes: 3

Related Questions