I have an external storage which I am wanting to store encrypted files.

Strategy #1:

  • Each file and folder name is AES encrypted with its own data key
  • All data keys are saved into a single datakeys.json file at the same storage location as all of the encrypted files.
  • The datakeys.json file is AES encrypted using a main key.
  • The main key is encrypted using a users RSA public key.

Strategy #2:

  • Each file and folder name is AES encrypted with its own data key

  • Every single Data key is encrypted using a main key, and stored next to the file

  • main key is encrypted using the users public RSA key and stored off the storage location


  • When I want to share the files with another user I encrypt the main key using the new users RSA public key.

  • Users can have their access revoked by removing their personal RSA encrypted main key. Also their access token (oauth) is revoked to the storage location. Datakeys.json is only loaded in memory when application is first run, and removed when closing.

  • User has access to all files and folders on the storage location, no need for file level sharing

  • Users are able to decrypt new items added to the external storage by getting an updated version of datakeys.json file.

Security Concerns

  • My main concern is the datakeys.json file containing ALL of the data keys for ALL of the files on the storage location.
  • Attacker gets access to the storage location (stolen oauth access token) and can somehow view the files
  • Datacenter can view the files

Weakest Link:

The weakest link (that I can think of) will be the users device, which will store their own private rsa key. If the device is compromised, then the storage location can be decrypted. This is an acceptable risk.

Each user will only be a small trusted group, so if they somehow store the main key after getting their access revoked that should be ok (they won't be able to access the external storage anyway because their oauth access token will have been revoked as well), or perhaps the data keys should be re-encrypted with a new main key upon revoking any new users access (this might be pointless as the user may have cached the data keys).

Another weak link (I think) is storing all of the data keys in a single aes encrypted json file (strategy #1) in the external storage. If that file is compromised then the entire external storage can be decrypted. Alternatively the data keys json file can be stored on a different secure server and accessible via an API. Creating a separation between the both the external storage and the data keys json.

Any advice?

Your Answer

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

Browse other questions tagged or ask your own question.