I want to implement a server side application with REST API - clients are browser and mobile app. User will have a login (email, password) and will store his files on the server. These files must be encrypted so that admins or anyone with access to the DB or filesystem wont have any possibility to open these files. Here are my questions regarding this issue:

What is the best way to store encrypted data on the server with using RSA - where as only authorized frontend user would have access to it? Third party should not have access to data, even if FTP access is given. In this case, private key can be "closed" by a user password. User password is only entered on authorization and is not available later on.

My ideas on this topic:

  1. Storing the private key (encrypted by server) without password in the user session. But in this case, if one has access to server, files can be de/encrypted.
  2. Storing the private key (encrypted by server) without password on the client's side (in webbrowser) and passing it on request to the server when an encryption process is needed. Here again, a third party with access to the server could intercept the transfer of the key and then encrypt user's files.
  3. Storing of private key without password on clients side and decrypting files on client's side. This may work with mobile Apps, but not on browser.

1 Answer 1


As long as the administrators of the server cannot be trusted any kind of key management, encryption or decryption should not be done on the server or through code provided by the server (like a program downloaded from the server or Javascript from the server).

This means these actions need to be done either by a fully trusted third party or by renting computing power from a trusted third party or by the user itself on its own (trusted) system. The latter might be achieved with standalone apps (from a trusted source). In the browser this could be done with some extension from a trusted source. It could not be done with extension or HTML+script loaded from the untrusted server since this could have been manipulated by the malicious admin.

  • Thanks! Is there any JS based de/encryption mechanism for the web-browser? I wouldn't like to use third party systems for this.
    – Kosha Misa
    Commented Sep 26, 2019 at 11:33
  • @KoshaMisa: There is WebCryptoAPI. But note that the client cannot trust the server to provide encryption using this API since the server could send something different to the client which contains some backdoor or similar. Commented Sep 26, 2019 at 11:50
  • Thanks. Do I understand it right, that in this case the key must be stored somewhere in the browser? What if the user changes the browser or reinstalls it?
    – Kosha Misa
    Commented Sep 26, 2019 at 14:53
  • @KoshaMisa: tricky. But this is actually the same with user reinstalling the OS. You need to find a way for the user to get the secrets from the browser. You might also store the keys encrypted on some untrusted server and the user only needs to remember the password. Of course, in this case the password needs to be hard enough to brute force. Commented Sep 26, 2019 at 15:21
  • yes, I thought of letting him download the pair.
    – Kosha Misa
    Commented Sep 26, 2019 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .