【问题标题】:How to encrypt a stream in node js如何在节点js中加密流
【发布时间】:2020-07-22 00:43:21
【问题描述】:

如何在 node js 中加密和解密流而不将文件保存在本地或将其转换为缓冲区。 如果没有办法,请提供内存高效且存储消耗更少的方式来加密和解密节点 js 中的流,以便我可以通过 api 直接将流上传到谷歌驱动器。

【问题讨论】:

    标签: node.js encryption node-streams nodejs-stream node-crypto


    【解决方案1】:

    我终于得到了这个问题的解决方案。我在这里为所有需要这个的人发布答案
    我正在使用一个名为 aes-encrypt-stream 的库
    或者您也可以使用 crpto 库或任何其他库。 这里

    使用 stream.PassThrough
    这里 file.stream 是我的输入流
    stream 是我的输出流
    从这段代码中,我能够减少服务器的内存消耗以进行加密

    const { createEncryptStream, createDecryptStream, setPassword } = require('aes-encrypt-stream');
    setPassword(Buffer.from('your key here', 'hex'));
    PassThroughStream = require('stream').PassThrough,
    stream = new PassThroughStream();
    await createEncryptStream(file.stream).pipe(stream);
    

    现在流已加密

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-09
      • 2020-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      • 2018-11-03
      • 1970-01-01
      相关资源
      最近更新 更多