我正在寻找在数据库中存储敏感数据的最佳解决方案。
我知道这是一个常见的问题,而且我已经做了我的功课(至少我是这样认为的),但在做出决定之前,我想在这里问问。
假设:
- 加密的数据需要被解密。我们谈论的是SMTP凭据,如用户名、密码、主机、端口等。
我考虑了两个概念:
Encrypt data with help of passlib.totp library. To make those data a bit safer i will keep key in separate file. Then from what i can see i can use this library to decrypt data to plain text using my key.
The other concept was to encrypt and decrypt data during query request with help of postgres:
insert into demo(pw) values ( encrypt( 'data', 'key', 'aes') );
And:
decrypt(pw, 'key', 'aes'), 'utf-8')
Here the key will be stored also in separate file.
所以我的问题是:
- 在代码中还是在数据库中加密/解密数据的方法更好?
- 有没有比passlib.totp更好(更强大)的库可用 -> 我对该库没有经验(我知道加密/解密不是存储密码最安全的方式 -> 密码应该被哈希,但我需要明文密码来使用用户smtp网关)。