-2
任何人都可以說如何加密和解密node.js中的jsonfile。我試過這個程序,它顯示一個錯誤,因爲文件密碼tty.setrawmode不是一個函數。加密和解密node.js中的json文件
明文文件:
{
"production" : {
"db" : {
"database" : "mysql",
"user" : "root",
"password" : "bdwb ve13hb3"
},
"app" : {
"port" : 8086
}
}
}
加密:
var SecureConf = require('secure-conf');
var sconf = new SecureConf();
sconf.encryptFile(
"./test.json",
"./test.json.enc",
function(err, f, ef, ec) {
if (err) {
consoel.log("failed to encrypt %s, error is %s", f, err);
} else {
console.log("encrypt %s to %s complete.", f, ef);
console.log("encrypted contents are %s", ec);
}
}
);
解密:
var SecureConf = require('secure-conf');
var sconf = new SecureConf();
var ef = "./test.json.enc";
var express = require('express');
var app = express();
sconf.decryptFile(ef, function(err, file, content) {
if (err) {
console.log('Unable to retrieve the configuration contents.');
} else {
var config = JSON.parse(content);
app.listen(config.production.app.port);
}
});
兄弟,我無法得到輸出。我按照你的指示。我添加了第三個參數作爲文本。我運行加密程序作爲webstorm終端中的第一個。它顯示相同的錯誤。你給我發送確切的代碼加密和解密。這是我的郵件ID:[email protected]提前。我在等待您的回覆... – vigneshRavi
對不起,但我不是你的兄弟。我偷看了'sconf.encryptFile'的源代碼,這是應該發生的事情。我沒有真正運行這個代碼。 –