加密并保存数据库中用户的第三方API秘密是安全的吗?



我想将用户的第三方API Secret(如AWS(存储在数据库中。泄漏可能会导致我的用户造成潜在的损失。它应该保密。

那么,如何在nodejs平台上保护他们的数据?我正在考虑加密和存储商店的秘密密钥,以使入侵者无法直接可见。

关于如何维护更多安全性的任何建议?

var crypto = require('crypto');
var assert = require('assert');
var algorithm = 'aes256'; // or any other algorithm supported by OpenSSL
var key = 'password';
var text = 'I love kittens';
var cipher = crypto.createCipher(algorithm, key);  
var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex');
var decipher = crypto.createDecipher(algorithm, key);
var decrypted = decipher.update(encrypted, 'hex', 'utf8') + 
decipher.final('utf8');
console.log(encrypted);
console.log(decrypted);
assert.equal(decrypted, text);

使用crypto.createcipheriv是一种使其更安全的一种方法。生成一个随机的iv并存储它。另外,您可以添加盐以使您的加密更安全。

最新更新