【发布时间】: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);
【问题讨论】:
-
我投票结束这个问题,因为它属于Information Security Stack Exchange。
标签: node.js security encryption