TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

22 pointsby deideiover 2 years ago
Hey HN,<p>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.<p>1. What are the best practices for storing client secrets and API keys in a DB?<p>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&#x2F;cons of each option?<p>3. What are some good encryption libraries in Node.js (I want to avoid rolling my own crypto)?<p>4. At what frequency should I rotate keys? What are some methods to handle key rotation?<p>Thanks a lot!

9 comments

ameminatorover 2 years ago
Assuming you are using SQLite, an extension exists which will likely do the job: <a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;see&#x2F;doc&#x2F;trunk&#x2F;www&#x2F;readme.wiki" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;see&#x2F;doc&#x2F;trunk&#x2F;www&#x2F;readme.wiki</a><p>Other databases will also have encrypt&#x2F;decrypt APIs available.<p>Specific answers to your questions will depend on your application and use cases (local network? global website? credit card data? health data? etc...).
评论 #34632914 未加载
fulafelover 2 years ago
Key management is the interesting part, although it&#x27;s possible to screw up just in the crypto part as well. Encryption is just a way of substituting the trouble of keeping the key secret vs keeping the data secret.<p>You&#x27;re going to match your key management to your threat model.<p>What are you going to do to keep the key safe in the scenarios of your threat model where an adversary can access the DB contents?
评论 #34638747 未加载
comprevover 2 years ago
Look into something like HashiCorp&#x27;s Vault for storing sensitive data.<p>Trying to roll your own is asking for trouble!
评论 #34632945 未加载
评论 #34635546 未加载
评论 #34633181 未加载
danielmarkbruceover 2 years ago
<a href="https:&#x2F;&#x2F;www.microfocus.com&#x2F;en-us&#x2F;cyberres&#x2F;data-privacy-protection" rel="nofollow">https:&#x2F;&#x2F;www.microfocus.com&#x2F;en-us&#x2F;cyberres&#x2F;data-privacy-prote...</a>
ianpurtonover 2 years ago
You want to look at acra which intercepts your postgres calls and adds encryption.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;cossacklabs&#x2F;acra">https:&#x2F;&#x2F;github.com&#x2F;cossacklabs&#x2F;acra</a>
评论 #34647178 未加载
simneover 2 years ago
It depend on context, for which You asking.<p>If it to obey laws, this question of regulations of Your country;<p>for b2b market, each industry have their industry-wide typical use cases;<p>for internal use other consideration;<p>for box product other.
评论 #34632969 未加载
goralphover 2 years ago
If you’re using a cloud provider like AWS I’d recommend their dedicated solutions for this problem - for AWS it’s Secrets Manager
评论 #34633447 未加载
_448over 2 years ago
Which DB?<p>Some DBs have in built support while others require plugins. The answer will depend on your DB and usecases.
评论 #34638723 未加载
mharigover 2 years ago
Best practice is to NOT store them. At least not on server side.
评论 #34638768 未加载