Building an end-to-end encryption framework in Swift

2016 @


I — Diffie-Helman key exchange algorithm.
  • Salt : (common paint) is the same and is know only by Alice and Bob, and can be seen as starting “password” between Alice and Bob.
  • Public Key : Both Alice and Bob have one and there is no problem if more entities know then.
  • Private key : (Secret colours) Both Alice and Bob have one, and only Alice know his Private key and only Bob know his Private key either.
AliceSecret = Salt + Alice.PrivateKey + Bob.PublicKey
BobSecret = Salt + Bob.PrivateKey + Alice.PublicKey

II — Building

Building the basic operations

First tests

  • Alice (our sender entity) and Bob (receiver entity), both with Public and Private keys.
  • A Salt (common paint).
  • A secret message “my secret”.
  • Symmetric key exchange (line 4 and 8).
  • Encryption latter (line 5) by Alice using the common Salt, her Private Key a Bob Public Key.
  • Decryption by Bob (line 9) using the common Salt, his Private Key a Alice Public Key.

III — Testing on real App-Server-App use case

GIF at :

IV — Materials

  • All the code used on this articles, as for the sample client app and server app, can be found at RJSP_Security
  • If you are not familiar with Vapor (server app) and you want to learn more, this article will help you for sure.

V — Final notes

VI — Article review by



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store