数据解密将使用RSA/ECB/OAEPWithSHA-256AndMGF1Padding算法在JAVA中运行。RSA/ECB/OAEPWithSHA-256AndMGF1Padding所以我必须使用相当于中的算法用公钥加密数据node.js。
我尝试crypto.publicEncrypt(key, buffer)使用 crypto.constants.RSA_PKCS1_OAEP_PADDING ,它与上述算法不相似。所以我需要相当于“RSA/ECB/OAEPWithSHA-256AndMGF1Padding”的算法或如何在node.js中实现相同的效果
我正在读取文件,对其进行压缩和加密,然后在网络上上传/写入。但我需要知道最终流的内容长度(通过读取、压缩、加密后返回的流)才能发出发布请求。
let zlib = zlib.createGzip(),
encrypt = crypto.cipherIV(....),
input = fs.createReadStream('file.jpg');
function zipAndEncrypt(){
let stream = readStream.pipe( zlib).pipe( encrypt );
let options = {
"stream_length":0,
headers: { "content-type": 'image/jpeg',
"content-length": '123456', // need to get this length
.....
}
}
// post the stream
needle( 'post', url, stream, options )
.then( resp => { console.log( "file length", resp.body.length);})
.catch( err => {})
}
Run Code Online (Sandbox Code Playgroud)
如果我在标题中输入正确的内容长度(在这种情况下我知道长度),上面的代码就可以工作。所以我需要找到流的长度。
到目前为止,我通过以下方式达到了长度:
let chunk = [], conLength;
stream.on( 'data', ( data ) => {
chunk.push( data ); …Run Code Online (Sandbox Code Playgroud)