首页 > 解决方案 > 如何在节点中使用 ssl 制作服务器?

问题描述

尝试使用 SSL 在节点上创建服务器时出错。我所做的如下:

首先,我生成了密钥对和这样的 CA:

1 - 我生成了私钥:

openssl genrsa -out mykey.pem 1024

2 - 我生成了公钥:

openssl rsa -in mykey.pem -pubout > publickey.pub

3 - 我生成了 CA:

openssl req -new -x509 -key mykey.pem -out certificate.cer -days 1825

从那里我在节点中创建了选项:

options = {
    key: fs.readFileSync(pathKey),
    cert: fs.readFileSync(pathSSLCertificate)
};

其中pathKeypathSSLCertificate分别是私钥和公钥路径。

然后使用restify:

server = restify.createServer(options);

但是它给出了以下错误:

library: 'PEM routines',
function: 'get_name',
reason: 'no start line',
code: 'ERR_OSSL_PEM_NO_START_LINE'

使用https://www.sslchecker.com/certdecoder进行测试

显示消息:

格式不正确或 SSL 文件已损坏

标签: node.jssslopenssl

解决方案


推荐阅读