Javascript Can';t导入.pem文件以表达

Javascript Can';t导入.pem文件以表达,javascript,node.js,express,https,Javascript,Node.js,Express,Https,我来自一个无人回答的地方: 嗯,我发现了一些新的东西。我仍然无法导入我的证书,当我尝试执行我的Node/express应用程序时,它会失败,并出现相同的错误,但现在我认为fs包无法正确读取我的.pem文件 看一看: // Setup HTTPS const httpsPort = 3443; const options = { key: fs.readFileSync("./key.pem"), cert: fs.readFileSync("./cert.pem") }; consol

我来自一个无人回答的地方:

嗯,我发现了一些新的东西。我仍然无法导入我的证书,当我尝试执行我的Node/express应用程序时,它会失败,并出现相同的错误,但现在我认为fs包无法正确读取我的.pem文件

看一看:

// Setup HTTPS
const httpsPort = 3443;
const options = {
  key: fs.readFileSync("./key.pem"),
  cert: fs.readFileSync("./cert.pem")
};

console.log("KEY: ", options.key)
console.log("CERT: ", options.cert)

var secureServer = https.createServer(options, app).listen(httpsPort, () => {
    console.log(">> CentraliZr listening at port "+httpsPort);
});
我得到以下输出:

C:\Zerok\dev\centralizr>node index.js
KEY:  <Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 50 52 49 56 41 54 45 20 4b 45 59 2d 2d 2d 2d 2d 0d 0a 70 52 39 37 51 33 6f 50 5a 5a 59 75 39 46 6c 31 54 6d 30 0d 0a ... >
CERT:  <Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 45 4a 54 43 43 41 36 79 67 41 77 49 42 41 67 49 49 48 48 ... >
_tls_common.js:85
      c.context.setKey(options.key, options.passphrase);
                ^

Error: error:0906D064:PEM routines:PEM_read_bio:bad base64 decode
    at Error (native)
    at Object.createSecureContext (_tls_common.js:85:17)
    at Server (_tls_wrap.js:776:25)
    at new Server (https.js:26:14)
    at Object.exports.createServer (https.js:47:10)
    at Object.<anonymous> (C:\Zerok\dev\centralizr\index.js:29:26)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
C:\Zerok\dev\centralizer>node index.js
关键:
证书:
_tls_common.js:85
c、 context.setKey(options.key,options.passphrase);
^
错误:错误:0906D064:PEM例程:PEM_read_bio:bad base64解码
错误(本机)
在Object.createSecureContext(_tls_common.js:85:17)
在服务器上(_tls_wrap.js:776:25)
在新服务器上(https.js:26:14)
在Object.exports.createServer(https.js:47:10)
反对

所以。。。怎么了?为什么节点将这些文件读取为。。。十六进制缓冲区?我真的不明白

更新:

好的,多亏了德里克·布朗,我现在可以看到这两个文件的内容了,尽管我一直收到相同的错误:“bad base64 decode”:

\u tls\u common.js:85
c、 context.setKey(options.key,options.passphrase);
^
错误:错误:0906D064:PEM例程:PEM_read_bio:bad base64解码
错误(本机)
在Object.createSecureContext(_tls_common.js:85:17)
在服务器上(_tls_wrap.js:776:25)
在新服务器上(https.js:26:14)
在Object.exports.createServer(https.js:47:10)
反对。(C:\Zerok\dev\centralizer\index.js:29:26)
在模块处编译(Module.js:570:32)
在Object.Module.\u extensions..js(Module.js:579:10)
在Module.load(Module.js:487:32)
在tryModuleLoad时(module.js:446:12)
如果未指定编码,则返回十六进制缓冲区。您应该将编码指定为
utf8
(或您正在使用的任何文件编码),这样就不会发生这种情况:

const options = { key: fs.readFileSync("./key.pem", "utf8"), cert: fs.readFileSync("./cert.pem","utf8") };

Zerok您是否仔细检查了私钥的内容?它看起来不长,但应该是创建请求时生成的
.pem
文件。这些说明可能会有所帮助。我从来没用过StartSSL。这不是密码。创建私钥和公钥,然后使用外部证书颁发机构(StartSSL)对公钥进行“签名”,创建新的“签名”公钥。密码是私钥之外的密码。这是一种加密私钥的方法,这样只有您机器中的授权用户才能访问私钥。
const options = { key: fs.readFileSync("./key.pem", "utf8"), cert: fs.readFileSync("./cert.pem","utf8") };