亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

nodejs 方法 crypto.createCipheriv

nodejs 方法 crypto.createCipheriv

qq_花開花謝_0 2022-12-09 16:30:39
const crypto = require('crypto');const util = require('util');class AES {    constructor(key, iv) {        if (!key) throw new Error('A 32 byte / 256 bit key is required.');        if (!iv) throw new Error('Initialization vector is required.');        this.key = key;        this.iv = iv;    }    encrypt(data) {        let cipher = crypto.createCipheriv('aes-256-cbc', this.key, this.iv);        let encrypted = cipher.update(data, 'utf-8', 'hex');        encrypted += cipher.final('hex');        return encrypted;    }    decrypt(data) {        let decipher = crypto.createDecipheriv('aes-256-cbc', this.key, this.iv);        let decrypted = decipher.update(data, 'hex', 'utf-8');        decrypted += decipher.final('utf-8');        return decrypted;    }    static randomBytes = async bytes => {        let result;        result = await util.promisify(crypto.randomBytes)(bytes);        return result;    }    sha256(data) {        return crypto.createHash('sha256').update(data).digest('hex');    }}以上是我的代碼,我想知道加密和解密方法是否應該異步?使用我的測試數據執行時間不到 1 毫秒,但是如果有成千上萬的并發用戶,使用異步構建這些方法會更好嗎?我無法在早期的測試中承諾它們,所以我想也許模塊不能異步?
查看完整描述

1 回答

?
絕地無雙

TA貢獻1946條經驗 獲得超4個贊

使函數異步不會提高多個用戶的性能,特別是如果這是一個 REST 服務。你應該看看通過線程使用你的硬件。



查看完整回答
反對 回復 2022-12-09
  • 1 回答
  • 0 關注
  • 259 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號