user data encryption
how do people usually do user data encryption? I would like to basically encrypt (or hash) everything users save in the database, is saving a decryption key in environment vars on vercel/netlify etc. good enough? Or are there other ways that might be more suitable?
(this is data I need to decrypt in the front-end, not passwords or anything like that, just user generated content, think like notion notes)
9 Replies
Would you be able to provide more context for the problem being solved? From what is given, I’m struggling to determine why encryption is taking place and what benefit it provides.
what you're looking for is an asymmetrical encryption algorithm. as for the details to implement that is above my paygrade. I haven't done it in a long time
I second that but also wonder what the point of asymmetric encryption would be in this case. If the browser client is decrypting the data, then there’s no point in encryption since the decryption keys will most likely be accessible to anyone using the site, unless everything is SSR or a key pair is made per user.
encryption and hashing is not quite the same. Look into E2E encryption. This is what you are looking for.
hey all, thanks for the replies - I looked into it more, I will probably use hashing for comparing data and other optimisations, I wanted to not store user data in plain text in the database, that's the only problem I was trying to solve
I ended up using crypto-js AES to encrypt the data server side, just before sending it to the DB, with an environment variable as the key, then when I need to read it in the front-end it gets decrypted when fetching from the endpoint (also server side)
seems to work but I don't know if there are any potential issues with it yet
(this is all for a side project btw, non production or work code - just exploring)
Spot on with what I was about to suggest hahaha just wanted to make sure I had the context right. Sounds like a good solution!
thanks! Looking at E2E as well and I'm keen to try that out at some point, for now I'll go with this 😄 - the only thing I don't like about this approach is the key management, but it's definitely more than at the moment!
To be fair, the key management is a regular solution. It doesn't fully meet US Federal Security standards lol but it'll do for most applications that don't deal with PII.
If it's something you'd like to learn more about, tools like k8 helm or hashicorp vault are nice. It is geared towards devops/security infra work, but IMO it's never bad to have some knowledge there unless you absolutely hate it. AWS and Cloudlfare have their own secrets manager. Vercel has
sensitive secrets
which is really their only form of secrets management right now. The values get decrypted at build, so unless you SSH or get a terminal inside of the server instance, you shouldn't be able to get the env var value. I've used Vault before where we stored API keys and other sensitive items for multiple clients (fintech SaaS), and it's a relatively nice, dynamic experience. Didn't touch infra or management sides of it though.thanks, this is really helpful! I will look into these 👍 it's a whole area I've never looked into before, all this stuff gets managed by other people at work hah!