2017-03-14 1 views
-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); 
     } 
    } 
); 

암호 해독 : sconf.encryptFile이 세 개의 인수로 호출

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); 
    } 
}); 

답변

0

경우, 터미널에서 암호를 읽습니다.

sconf.encryptFile(
    "./test.json", 
    "./test.json.enc", 
    "this is not such a good password", 
    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); 
     } 
    } 
);

: 당신은 Node.js를에서 사용자의 문자를 수용 할 수있는 터미널에서 실행하지 않는 경우 당신은 세 번째 인수의 장소에서 스크립트에 암호를 추가해야합니다 암호 해독을 위해 정확히 동일한 암호를 제공해야합니다.

코드에 암호를 추가하는 것은 좋은 생각이 아닙니다. 공격자는 구성 파일을 암호화하는 데 사용 된 암호를 찾기 위해 코드를 조사하기 만하면됩니다.

+0

Bro, 출력을 얻을 수 없습니다. 지침을 따랐습니다. 텍스트로 세 번째 매개 변수를 추가했습니다. 암호화 프로그램을 웹 스톰 터미널에서 처음 실행합니다. 동일한 오류를 보여줍니다. 정확한 코드를 보내주십시오. 암호화 및 암호 해독. 이것은 내 메일 ID입니다 : [email protected] 미리 감사드립니다. 귀하의 회신을 기다리고 있습니다 ... – vigneshRavi

+0

죄송하지만, 나는 형제가 아닙니다. 나는'sconf.encryptFile'의 소스 코드를 들여다 보았습니다. 나는이 코드를 실제로 실행하지 않았다. –

관련 문제