4

Let's say, we develop a social network website, which allows to send personal messages between users. We don't want anyone (even us) to read these messages, except for message sender and receiver.

Is it possible?

  • 2
    Yes. Whatapps works like this way. – again Feb 23 '18 at 12:35
  • 2
    If you're interested in implementing a system, there are open source implementations like github.com/signalapp – Neil Smithline Feb 23 '18 at 14:36
  • 1
    Yes you need end-to-end encryption. Riot and Matrix do that. The keys reside solely in the user's client. – Chloe Feb 23 '18 at 19:38
3

What you are looking for is something called public key encryption.

Analogy

The analogy is that we have two people: Alice and Bob. Alice wants to send a message to Bob but they haven't met before in private, so they don't have any pre-established secrets/keys/etc.

Alice sends Bob a message saying "I want to send you a message. Please send me an open lock that you have the key to". This 'lock' is called a public key in the crypto world.

Bob sends Alice a copy of the open lock (since stuff can be easily duplicated in the crypto world). Alice puts her message in a box and locks the box with Bob's lock. Alice then sends the locked box to Bob.

Bob receives the box in the mail and uses his key (with only Bob has access to) to unlock the box. Bob can now take out the message and read it. In the crypto world, this private key is called, surprise surprise, the private key :)

The process of locking the message in a box so that others cannot read it is known as encryption

Implementation

The #1 rule in crypto is don't write your own crypto. That's because it's super easy to mess up, but that doesn't mean you shouldn't use an established crypto implemetation.

I recommend looking into JavaScript crypto libraries such as kbpgp, sjcl, tweetnacl, etc.

As mentioned by other users, a big problem with crypto and js is that users cannot know for sure that your server is serving the real javascript. A hacked server could send out code that says that it's encrypting stuff but is really siphoning it off to some evil 3rd party. At the same time, that worry is relevant whether or not you use crypto, so (imo) is shouldn't deter you from maning the world a better place by using cryptography

6

So what you probably want is public private keys.

User A sends his own public key to User B, User B can then encrypt messages using Users A's public key.

User B then sends back the encrypted message to User A, user A has a private key which matches the public key, user A must always keep this PRIVATE. Using the private key user A can decrypt the message from User B. Once Encrypted user B would not be able to decrypt the message, the public key is used for encryption only.

what you are looking for has been used in many technologies, I use a similar method day to day with PGP.

obviously you would design your application to take this into account to handle all of the key generation and store them on the persons device (never store them on your server)

Another method would be to user a preshared key and another type of encryption like AES, this however would require the sender and receiver to know the same key. problematic if you only talk online.

preshared key would mean the user would need a key for every conversation, while a PPK (public and private) would mean that many people could have a users public key and the user hold securely on to that private key.

  • 3
    Of course, if you develop a website, it's difficult to convince the user that you don't know his private key, since the whole system is stored on your servers. You'll have to do the whole key management and encryption/decryption in a javascript library that downloads the private key which is stored on the server and decrypts it locally, then uses it to decrypt messages locally, and even if you do all that, it still won't be impossible for you to read messages because what's to keep you from manipulating the javascript you send to the client so that it spies on your clients? – Pascal Feb 23 '18 at 14:54
  • @Pascal you are very right, sad thing is there is only so much you can trust any 3rd party. most of that trust is blind trust too. the only true solution to a secure communication requires a series of tin foil hats, an underground Faraday cage and interpretive dance. (or somewhere in the middle, like making your own app for your own use, using P2P with new keys generated each session and stored in memory only) – TheHidden Feb 23 '18 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.