1

I'm new to the whole cryptography thing and I want to implement it in my app to store non-personal user data. I've been trying to get my head around the whole thing by reading articles and questions etc.

I want to encrypt some non-personal user data related to my app. It is only the single user that should ever be able to decrypt data on their own devices so the server or anyone else should never be able to read the data. As I'm using third party auth providers I don't have access to users password hashes so my current plan was as follows:

  1. Random number key - When the user signs up create a random number using a CSPRNG to use as the key to encrypt user data.
  2. Recovery key - Generate a recovery key (6 digit code for example) and hash it using PBKDF2 or Argon2 and then encrypt the random number key using the hash output and store this key in the database.
  3. Storing the recovery key - Store the recovery key on the user's device in secure encrypted storage such as keychain for iOS and keystore for Android
  4. Decrypting data - Whenever we need to decrypt data we can pull the key from the database with the encrypted data and use the recovery key stored securely on the users device to decrypt the data.
  5. Resetting the recovery key - if a user wants to reset a recovery key we can simply decrypt the encryption key and then repeat step 2.

Does this encryption method seem safe to use for this purpose?

Is this symmetric or asymmetric as there are two keys involved with the encryption process meaning only the user with the key on their device can decrypt?

Thanks.

3
  • This is symmetric, because you are essentially using the same key to encrypt/decrypt. Asymmetric encryption is used in public key cryptography when the public key encrypts and the private key decrypts. Feb 16 at 14:07
  • Thanks, would this still be considered a safe method of encrypting user data as long as keys are only stored on users devices?
    – Jack_b_321
    Feb 16 at 14:13
  • Not sure about the cryptographic strength, that 6-digit recovery key would be a weakness - not enough entropy. There should already be a solution for this, try searching for something like "user data at rest encryption". You, being new to cryptography, might not be aware of one of the main principles: don't roll your own crypto:) Feb 16 at 15:04

1 Answer 1

0

Is this symmetric or asymmetric as there are two keys involved with the encryption process meaning only the user with the key on their device can decrypt?

It's symmetric, as asymmetric encryption uses a pair of public and private keys, while your scheme uses only private keys.

You do have two keys, but they are both private keys. For asymmetric encryption, you would have a pair of keys, one public (for encryption) and one private (for decryption). This is eg useful when different people need to write and read data (eg one person sending a message to another person). For your use-case, I see no benefit with asymmetric encryption.

Does this encryption method seem safe to use for this purpose?

A 6 digit code doesn't offer enough security (especially for offline attacks, which is what we are worried about here). So you will need to assume that cracking the recovery key hash is trivial, as is decrypting the random number key (which is encrypted with the recovery key). Though I'm not sure what the recovery key is used for (it can't be used to recover the data if the device the keys are stored on is lost, as no keys leave the device).

If we strip that layer away, what is left is (as I understand it) an encryption of the data on the users device with a key stored on the users device. The encrypted data is then sent to the server. No key is ever sent to the server. When accessing the data, the encrypted data is fetched from the server and decrypted on the users device.

Assuming a non-compromised user device, this is secure for the stated purpose (assuming the encryption algorithm meets your needs).

You may run into problems when the server is compromised (eg for a web app, an attacker could modify the JavaScript code sent to the client to read out users keys). But at rest, the data is secure.

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.