【发布时间】:2023-03-22 10:52:01
【问题描述】:
您好,当我尝试在 ubuntu 上运行我的 sell.js javascript 时出现此错误:
节点卖.js
socket timed out
socket closed
connecting to 72.165.61.175:27018
connected
encrypt request
/var/www/bot/node_modules/steam/lib/steam_client.js:150
var cryptedSessKey = require('crypto').publicEncrypt(fs.readFileSync(__dirna
^
TypeError: Object #<Object> has no method 'publicEncrypt'
at SteamClient.handlers.(anonymous function) (/var/www/bot/node_modules/steam/lib/steam_client.js:150:42)
at SteamClient._netMsgReceived (/var/www/bot/node_modules/steam/lib/steam_client.js:106:26)
at Connection.emit (events.js:95:17)
at Connection._readPacket (/var/www/bot/node_modules/steam/lib/connection.js:50:8)
at Connection.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
at readableAddChunk (_stream_readable.js:166:9)
at Connection.Readable.push (_stream_readable.js:128:10)
at TCP.onread (net.js:529:21)
/var/www/bot/node_modules/steam/lib/steam_client.js 中的代码:
handlers[EMsg.ChannelEncryptRequest] = function(data) {
this._connection.setTimeout(0);
this.emit('debug', 'encrypt request');
this._tempSessionKey = require('crypto').randomBytes(32);
var cryptedSessKey = require('crypto').publicEncrypt(fs.readFileSync(__dirname + '/public.pub'), this._tempSessionKey);
var keyCrc = require('buffer-crc32').signed(cryptedSessKey);
var encResp = new schema.MsgChannelEncryptResponse().encode();
var body = new ByteBuffer(encResp.limit + 128 + 4 + 4, ByteBuffer.LITTLE_ENDIAN);
body.append(encResp);
body.append(cryptedSessKey);
body.writeInt32(keyCrc);
body.writeUint32(0);
this._send(EMsg.ChannelEncryptResponse, body.flip());
};
我做了 npm install --save crypto 但它不起作用我总是收到这个错误。如果有人知道如何解决这个问题,请告诉我。
【问题讨论】:
-
你已经在 ubuntu 中安装了 build-essentials 吗?一些 NPM 包需要这些来编译依赖。
-
@manuerumx 我安装了它现在尝试再次运行脚本但同样的错误..
-
您使用的是哪个版本的节点?请注意,如果您从 ubuntu 存储库安装节点,则您拥有旧版本 0.10 或 0.12 这些版本没有 crypto.publicEncrypt 功能。您需要升级到分支 4.x 或 5.x,为此,您需要手动安装 node.js
-
@manuerumx 似乎节点的版本是我遇到的问题 0.10 谢谢你可以回答,我会评价它是正确的
标签: javascript node.js ubuntu