The community forums are in BETA and closed to the public.

Cryptography and Encryption of Data Streams like WebSockets and HTTP Streaming

Cryptography and Encryption of Data Streams like WebSockets and HTTP Streaming

Streaming data cryptographically over PubNub data streams is really easy but you have a lot of options. When we talk about using a Cipher Key over a WebSocket Connection we are typically discussing symmetric key encryption in which AES 256 is essentially the standard option today. When you are in a conversation about sending secured/encrypted data over websocket connections using asymmetric keys this is almost always an RSA Public/Private key pair strategy.

JavaScript AES256 over WebSockets and other Data Streams Protocols

The following JavaScript example will show you how to send and receive encrypted JSON payloads over bidirectional streaming TCP sockets with PubNub. Notice the cipher_key parameter in the config section.

<script src=https://cdn.pubnub.com/pubnub.min.js></script>
<script>(function(){
    var secure_pubnub = PUBNUB.init({
        publish_key   : 'demo',
        subscribe_key : 'demo',
        ssl           : true,
        cipher_key    : 'my-super-secret-password-key'
    });
})();
</script>

By setting the "cipher_key" : "your-secret-code" in your PubNub Init, you enable full AES256 Crypto for all send/receive publish/subscribe commands.

For an RSA public/private key cryptography configurations, refer to our Babel Secure Chat with RSA key generation and key exchange.


Comments to this discussion are now closed!