gpt4 book ai didi

javascript - Node.js 代理请求并使用 AES 对其进行加密

转载 作者:行者123 更新时间:2023-12-02 18:16:41 24 4
gpt4 key购买 nike

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

关于javascript - Node.js 代理请求并使用 AES 对其进行加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19230277/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com