带有express的socket.io中的SSL:缺lessPFX或证书+私钥。

我想通过SSL与socket.io套接字。 我读过其他答案,但没有任何工作

这是我的代码:

var ssl_options = { key : fs.readFileSync(my_key_path), cert : fs.readFileSync(my_cert_path) }; var protocol = "https"; preparedApp = require(protocol).createServer(ssl_options,app); var io = require('socket.io')(preparedApp); preparedApp.listen(8080, function(){}); io.on('connection', function(socket){}); 

这里是我的ssl_options的日志…

 { key: <Buffer 41 ...>, cert: <Buffer 4a ...> } 

这个错误与标题throw new Error('Missing PFX or certificate + private key.'); 。 有谁知道可能会发生什么? 这个答案的其他解决scheme没有解决我的情况。

使用PEM(RSA)格式作为您的私钥。 检查私钥是否被base64编码,包含在“—– BEGIN RSA PRIVATE KEY —–”和“—– END RSA PRIVATE KEY —–”之间

从文档:

  • key:包含PEM格式的服务器私钥的string或缓冲区
  • cert:持有PEM编码证书的string
  • 密码:私钥或pfx的密码string[可选,默认值:null]

要么

  • pfx:持有PFX或PKCS12编码的私钥,证书和CA证书的string或缓冲区

将私钥转换为RSA PEM: openssl rsa -in <PATH TO KEY> -out key.pem -outform PEM

要创buildPKCS#12包,请使用openssl pkcs12 -export -in cert.pem -inkey key.pem -certfile ca.pem -out host.pfx

– 附加 –

确保证书是PEM编码运行openssl x509 -in <PATH TO CERT> -out cert.pem -outform PEM