I'm in the process of encrypting the user data on my app and have adopted the scheme in this answer to secure user emails, passwords, name and other private details. I'm using an AES surrogate key and a locking key generated from the password.

So far, so good.

However, I've realized that when I come to the user's status (like a Facebook feed), it's not so straight forward.

Of course, I can encrypt and recover the user's status with the scheme above. But how do I get the status of their friends to show on the user's feed? According to the scheme above, I would need to have the friend's password in order to decrypt this. By design, I never see the friend's password, and the user only knows their own password.

The only way I can find is something like this answer that uses a document key and user key implementation.

Do I really have to go to the lengths of implementing OpenPGP?

When a user adds friends, do I then have to somehow add their key to all of the previously encrypted documents? Doesn't seem feasible. How do the social media companies do it?


The "social media companies" probably do not encrypt data like that when at rest. Generally speaking, the only data that is likely to be encrypted at rest is that data which is intended only to be accessed by the user themselves. (Which is not much for most social media systems.)

Though the companies may use some form of full-disk or database encryption, I would be surprised if they used per-user keys for data that is meant to be shared (even with a small set of users).

If you want to be able to encrypt data from one user, and have another user decrypt it without a shared key, you will need some kind of public key cryptography. (This is essentially the definition difference between asymmetric and symmetric cryptography.) There's no need to do OpenPGP if you want to keep the data within your own service, you can use something like NaCL or libsodium to perform your cryptographic operations.

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.