凭借PhantomJS,CasperJS允许您指定在应用程序启动时加载的 JSON文件.我的凭据存储在此文件中,这比在源文件中硬编码要好一些: var json = require('testfile.json');var username = json['username'];var myke
var json = require('testfile.json'); var username = json['username']; var mykey = json['mykey'];
我仍然将我的凭证以明文形式存储在服务器上,我想远离它.此过程将自动执行,因此我无法在每次运行时通过命令行参数传递凭据,也不想将参数存储在Windows任务计划程序中.什么是安全存储这些信息的安全方法?
使用此页面上列出的功能: http://lollyrock.com/articles/nodejs-encryption/我能够根据自己的需要构建以下概念证明:
var crypto = require('crypto'); var algorithm = 'aes256'; var password = 'correcthorsestaplebattery'; var string = "Something I\'d like to encrypt, like maybe login credentials for a site I need to scrape."; console.log('\n\nText: ' + string); var encrypted = encrypt(new Buffer(string, "utf8"), algorithm, password); console.log('\n\nEncrypted: ' + encrypted); var decrypted = decrypt(encrypted, algorithm, password).toString('utf8'); console.log('\n\nDecrypted: ' + decrypted); // check to prove 2-way encryption works console.log('\n\nAre they the same before and after crypto? '); console.log(decrypted == string); function encrypt(buffer, algorithm, password){ var cipher = crypto.createCipher(algorithm,password) var crypted = Buffer.concat([cipher.update(buffer),cipher.final()]); return crypted; } function decrypt(buffer, algorithm, password){ var decipher = crypto.createDecipher(algorithm,password) var dec = Buffer.concat([decipher.update(buffer) , decipher.final()]); return dec; }
这使用AES256,它应该像双向加密一样安全,尽管我还不够先进,无法评论实现.无论如何,它比纯文本更好.
从这里,您可以轻松地将输出写入文件而不是控制台,如图所示.只要您只是解析包含JSON的文件,您就必须在解释之前添加解密步骤.
我希望这有帮助.