Live data from Hacker News

Ask HN: How to encrypt data in a SQL database?

news.ycombinator.com

1–10 of 31 posts

Ask HN: How to encrypt data in a SQL database?

#1
Hey HN,

I will need to store some sensitive data (API keys, Client Secrets) of my customers in my DB. I was wondering if anyone could help me with these questions.

1. What are the best practices for storing client secrets and API keys in a DB?

2. Should the encryption be handled in the application level (using a library built on top of Node Crypto) or the database level (with pgcrypto)? What are the pros/cons of each option?

3. What are some good encryption libraries in Node.js (I want to avoid rolling my own crypto)?

4. At what frequency should I rotate keys? What are some methods to handle key rotation?

Thanks a lot!

Re: Ask HN: How to encrypt data in a SQL database?

#4
Assuming you are using SQLite, an extension exists which will likely do the job: https://www.sqlite.org/see/doc/trunk/www/readme.wiki

Other databases will also have encrypt/decrypt APIs available.

Specific answers to your questions will depend on your application and use cases (local network? global website? credit card data? health data? etc...).

Re: Ask HN: How to encrypt data in a SQL database?

#6

Assuming you are using SQLite, an extension exists which will likely do the job: https://www.sqlite.org/see/doc/trunk/www/readme.wiki Other databases will also have encrypt/decrypt APIs available. Specific answers to your questions will depend on your application and use cases (local network? global website? credit card data? health data? etc...).

>Specific answers to your questions will depend on your application and use cases (local network? global website? credit card data? health data? etc...)

Thank you so much for the reply! My application is a SaaS that helps developers add integrations (with apps like Slack, Linear etc.) to their apps really quick. The kind of sensitive data is Client Secrets and Access Tokens.

Re: Ask HN: How to encrypt data in a SQL database?

#7
post #3

Look into something like HashiCorp's Vault for storing sensitive data. Trying to roll your own is asking for trouble!

Thanks for the reply. I'm fully aware of the dangers of rolling my own and want to avoid it at all costs. Is using a battle-tested Node.js library or the database's own API for encryption also dangerous?

Re: Ask HN: How to encrypt data in a SQL database?

#8
post #5

It depend on context, for which You asking. If it to obey laws, this question of regulations of Your country; for b2b market, each industry have their industry-wide typical use cases; for internal use other consideration; for box product other.

Hey, thanks for the reply. My application is a SaaS that helps developers add integrations (with apps like Slack, Linear etc.) to their apps really quick. What is the best way to securely store Client Secrets, Api Keys and Access tokens? Please let me know if you know of any external services too that can help with this.
Post reply on HN