我在 Node.js 中生成的私钥在 Go 中不被识别为 PEM 格式
php小编西瓜在最近的开发过程中遇到了一个问题,他发现在使用Node.js生成的私钥在Go中无法被识别为PEM格式。这个问题困扰了他很长时间,他尝试了各种方法来解决这个问题,但都没有成功。在这篇文章中,我们将探讨这个问题的原因以及可能的解决方法,帮助读者解决类似的困扰。
问题内容
我使用加密库和以下代码在 node.js 中生成了公钥和私钥。
function generatekeyfiles() { const keypair = crypto.generatekeypairsync("rsa", { moduluslength: 4096, publickeyencoding: { type: "spki", format: "pem", }, privatekeyencoding: { type: "pkcs8", format: "pem", cipher: "aes-256-cbc", passphrase: "", }, }); // writing the keys in the following files fs.writefilesync("public_key", keypair.publickey); fs.writefilesync("private_key", keypair.privatekey); }登录后复制