Free up to 1MM monthly messages. No credit card required.
In this blog post, we’ll walk you through sending and receiving encrypted chat messages. We’ll demonstrate how Babel shares 1024-bit RSA public keys where chat participants will use these keys to send encrypted chat message. Along the way, we’ll also build a messaging system for encrypted chat messages with PubNub. Additionally the asymmetric encrypted payload will be delivered over XMPP and WebSocket streaming 2048-bit SSL TLS connects.
Here’s what we’ve covered so far:
This is a five part series on building Babel, an open source chat widget and API built with PubNub. Babel allows you to send and receive self destructing, encrypted chat messages and exchange 1024-bit RSA public keys in a chatroom.
We have to subscribe to a channel and set our state to our username and public key. While we’re subscribing, we’ll also declare two functions,
onPresence, which we’ll initialize later.
We can get the public keys of all users currently subscribed to a channel simply by calling
state enabled and then storing the data into our
users object, which contains a mapping of usernames to their public keys.
onPresence will be called whenever a user leaves or joins the
babel channel. So in order to keep
users up to date, we’ll call initialize
onPresence to call
here_now and update
users every time it’s called.
Step 3: Encrypted Chat Messaging over WebSockets
Now, let’s implement a function to send encrypted messages to other users.
sendMessage takes a username and a message to send. If
recipient is actually the username of a current user, then
sendMessage will encrypt the message with the recipient’s public key, which is stored in the
users object, and publish a message containing the username of the recipient, the sender, and the encrypted message.
Because we now know what form the messages will be in, we can initialize
onMessage to properly handle messages. For now, we’ll enable
onMessage so that it recognizes when we’ve received an encrypted message, decrypts the message with our private RSA key, and prints the decrypted message out into the console.
That’s it! We’ve now built a key exchange system and walked you through how to send and receive encrypted messages. Next, we’ll show you how to self destruct your messages.
A roundtable discussion led by PubNub’s COO, Casey Clegg, exploring the topics of what it means to be human in a virtual world.
Dr. Joe Kvedar, Chair of the Board for the American Telemedicine Association, joins our COO, Casey Clegg, to discuss why...
Today, we are glad to announce that we are currently in the process of implementing ISO-27001 security standards.