1

I have a client-server system, where the client is an Android app. The client and the server communicate over HTTP.

If the server/network is not available, then the client has to store the data locally in an encrypted file and needs to retry to initiate the communication later, once the server/network has recovered.

There is a business requirement that these local files have to be encrypted somehow on the client, and if the client becomes damaged, the administrator needs to be able to recover the data from the local encrypted files. The data does not need to be encrypted while sending over the network.

I would like to know is what is the best way to encrypt the data? I have a potential solution in my mind, but not sure, whether it is correct/efficient or not:

I would encrypt the files with a symmetric key and share it with the server, so it can decrypt it. In order to keep the symmetric key in secret while sending it over the network, my plan is to encrypt the symmetric key with the server's public key, so only the server will be able to recover the symmetric key.

I do not want to re-invent the wheel, so I anyone knows any better, or simpler way to store and to encrypt temp data on the client, then please, share it with me. I am also looking for the name of the design-pattern that solves such a problem if there is any.

1
  • 1
    Does the client have to be able to decrypt the data? If not, then why not simply use an asymmetric keypair, with the client having the public and the server having the private. The client encrypts with the public, and sends to the server, who can decrypt.
    – Joe
    Feb 13, 2018 at 18:26

2 Answers 2

0

If the client has to only encrypt the data and decryption is not required at client side then you can simply use asymmetric key encryption and encrypt it at client using public key and decrypt it at server using private key.

If client needs to decrypt the data as well(Ex. for processing/presentation etc.) then you can use symmetric key encryption.

  • Key Derivation : You can use PBKDF2 to derive the key from user's password

  • Key Management: You can derive this key dynamically whenever it is required using user's password. Alternatively you can store it in Android keystore.

Note: Keep in mind that asymmetric key encryption is an expensive process in comparison to symmetric key encryption. Encrypting large files using asymmetric key encryption may take good amount of time that may affect performance of the application.

0

Threat modeling.

Who are you attempting to hide the data from? The user of the mobile device? If the admin needs to recover the data, why not just keep it on the server?

If you don't care about encrypting over the network, you don't care about the privacy of the data, so we need to understand what business purpose is served by encrypting on the device, if we are to provide a useful answer.

When you talk about a symmetric key protected by a public key, you are basically re-inventing https (TLS), in which case, just use that instead of http, and rolling your own.

If the client picks the symmetric key, it could decrypt the files locally, so you gain no protection there, and since the files aren't encrypted when originally sent over the network, I don't understand the business value/requirement to store them encrypted on the end device. A hostile end user could just capture the unencrypted files as they were sent.

If OP can flesh out the question with the reason for the requirement, we might be able to give better advice.

In the most abstract, what you describe would "work" but wouldn't really be protecting anything in any meaningful way.

You must log in to answer this question.

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