【问题标题】:Is it secure to encrypt and save third party API secret of users in Database?在数据库中加密和保存用户的第三方 API 机密是否安全?
【发布时间】:2017-06-07 10:28:57
【问题描述】:

我想将我的用户的第三方 API 机密(如 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);

【问题讨论】:

标签: node.js security encryption


【解决方案1】:

使用 crypto.createCipheriv 无疑是保持其更安全的一种方法。生成一个随机 IV 并存储它。您还可以添加盐以使您的加密更加安全。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-11
    • 2021-03-09
    • 1970-01-01
    • 2018-08-27
    • 2014-11-01
    • 2011-09-22
    • 2019-04-16
    • 2011-03-12
    相关资源
    最近更新 更多