簡體   English   中英

Node.js代理請求並使用AES對其進行加密

[英]Node.js proxy request and encrypt it using AES

在Express應用程序中,最簡單的方法是編寫將請求代理到另一台服務器並加密響應,然后再將其發送到客戶端(將在此處解密)的路由。 是否可以使用流來完成所有操作?

var request = require('request'),
    http = require('http'),
    crypto = require('crypto'),
    acceptor = http.createServer().listen(8089);

acceptor.on('request', function(r, s) {
    var ciph = crypto.createCipher('aes192', 'mypassword');

    // simple stream object to convert binary to string
    var Transform = require('stream').Transform;
    var BtoStr = new Transform({decodeStrings: false});
    BtoStr._transform = function(chunk, encoding, done) {
       done(null, chunk.toString('base64'));
    };

    // get html from Goog, could be made more dynamic
    request('http://google.com').pipe(ciph).pipe(BtoStr).pipe(s);


    //  try encrypt & decrypt to verify it works, will print cleartext to stdout
    //var decrypt = crypto.createDecipher('aes192', 'mypassword');
    //request('http://google.com').pipe(ciph).pipe(decrypt).pipe(process.stdout);
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM