在屏幕抓取应用程序中使用静止存储凭据的合理安全方法是什么?

借助PhantomJS,CasperJS允许您在应用程序启动时指定要加载的JSON文件。 我有我的凭据存储在这个文件,这是比在源文件中硬编码好一点:

var json = require('testfile.json'); var username = json['username']; var mykey = json['mykey']; 

我仍然将服务器上的凭据以纯文本forms存储,我希望远离这些凭据。 这个过程将被自动化,所以我不能通过命令行parameter passing凭据,也不会在Windows任务计划程序中存储参数。 什么是安全的方式来存储这些信息呢?

使用本页列出的function: http : //lollyrock.com/articles/nodejs-encryption/

我能够为我自己的需要build立以下的概念certificate:

 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,应该像2路encryption一样安全,虽然我没有足够的先进的评论的实施。 无论如何,它比纯文本更好。

从这里,您可以轻松地将输出写入文件而不是控制台,如图所示。 只要parsing一个包含JSON的文件,就可以在解释之前添加解密步骤。

我希望这有帮助。