I'm currently designing a mobile/desktop application synchronise some messages or notes. I'm searching a way to secure it and to avoid let the server being able to read the messages.

My goal is have a client which encrypt a message in client side, sending it to the server which stores it to the database. Then, if another client on the same account is connected, it will received the encrypted message, decrypt it and store it in his local cache.

I can't just use one of the standard end to end encrption because I don't want to have a different key each time I use the application. I want to be able to store the messages in the database.

An other constraint is that I don't want the user to manualy manage the keys. I just want a password for the account.

So, a solution I have imagined is to use an asymetric algorythm like RSA and a symetric one like Blowfish or CAST. I generate an RSA ket pair when the user create an account, encrypt it with CAST and the user's password as key and store the result localy on the phone. Then, the messages are encrypted with the public RSA key, sent to server and stored in the database. To be able to decrypt messages on an other client (like on the PC for exemple) I just send the encrypted key pair from the phone to the server that sent it back to the new client. The new client can now decrypt the RSA key pair with the user password and decrypt messages stored in the database.

Since I'm pretty new to all this stuff, I don't if this is a good idea or if there is a better way to do it.


You seem to be inventing your own ad-hoc protocol, without authenticated encryption, and using old algorithms with known security weaknesses such as small block size.

I strongly suggest you use a high level modern library such as libsodium and use its crypto_box function for authenticated encryption, as well as Argon for password key derivation to protect the private keys. This will supply fast modern authenticated encryption (which your proposed solution would not provide). There are libsodium "wrappers" for most popular high-level programming languages.

It is much more difficult to go wrong using a known-good, high-level toolbox such as libsodium. With out using something more pre-built, you will have to decide on many security-critical details which are easy to get wrong such as: symmetric modes, authentication mechanisms for your cipher text, padding, key generation, nonce generation and re-use protection, key-wrapping, padding, side-channel resistance, and encoding.

You will still have to compose a few high-level building blocks for your application with something like libsodium, but it won't be nearly as difficult or error-prone.

  • $\begingroup$ @Ella_Rise CAST and Blowfish are ancient, and suffer from a 64-bit block size if nothing else. Modern, well vetted algorithms like AES or Salsa/ChaCha are better in every way: faster, stronger, and with far more cryptanalysis in the literature. $\endgroup$ – rmalayter Oct 14 '16 at 17:33
  • $\begingroup$ @Ella_Rose edited per your suggestions $\endgroup$ – rmalayter Oct 14 '16 at 21:57

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.