简体   繁体   English

Firebaseapperror:无法解析私钥:错误:pem 格式的消息无效

[英]Firebaseapperror: failed to parse private key: error: invalid pem formatted message

I got this error firebaseapperror: failed to parse private key: error: invalid pem formatted message when I pushed my nodejs app to heroku.当我将我的 nodejs 应用程序推送到 heroku 时,我得到了这个错误firebaseapperror: failed to parse private key: error: invalid pem formatted message

I had my environment variables all set like this我的环境变量都是这样设置的

# .env file
    
project_id=project_id
private_key='-----BEGIN PRIVATE KEY----- ... ------END PRIVATE KEY-----\n'
client_email=client_email

And accessed them like so:并像这样访问它们:

export const sa = {
    privateKey: process.env.private_key,
    projectId: process.env.project_id,
    clientEmail: process.env.client_email
};

On my local everything worked fine, but on production (heroku) I got the error mentioned above.在我的本地一切正常,但在生产(heroku)上我得到了上面提到的错误。 The private key is a multiline environment variable and it couldn't be parsed.私钥是多行环境变量,无法解析。

Please, how do I fix this?请问,我该如何解决这个问题?

The Fix修复

How I fixed this was through a post I saw online: How to Store a Long, Multi-line Private Key in an Environment Variable我如何解决这个问题是通过我在网上看到的一篇文章: 如何在环境变量中存储长的多行私钥

Follow the step and you should fix this as well.按照步骤操作,您也应该解决此问题。

Brief summary of the post is this:这篇文章的简要总结是这样的:

Store the long, multi-line key as a json string like so像这样将长的多行密钥存储为 json 字符串

启用互联网

Then parse it and destruction the key like so然后解析它并像这样销毁密钥

在此处输入图像描述

This would work on local, but on production (heroku) you will get a parse error because of the single quote before and after the very key in question.这将在本地工作,但在生产(heroku)上,由于有问题的关键之前和之后的单引号,你会得到一个解析错误 Therefore, remove the single quotes before and after the key in your production env variable .因此,删除生产环境变量中键前后的单引号。 I also tried without the single quote on local and it worked .我也试过在 local 上不单引号它起作用了

Extra Benefit额外福利

Extra Benefit with this Method这种方法的额外好处

From this, you could make life easy for you by doing this由此,您可以通过这样做让生活变得轻松

启用互联网

Store the entire object as json string in your env variable.将整个 object 作为 json 字符串存储在您的环境变量中。

Then access it like so然后像这样访问它

启用互联网

That's it.而已。

Reminder: remember what I said about single quote提醒:记住我所说的单引号

Alternatively, getting rid of single/double quotes around private_key solved it in my case.或者,去掉private_key周围的单引号/双引号解决了我的问题。 You can set private key in your prod env variables as:您可以在 prod env 变量中将私钥设置为:

-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----

The most consistent result for me was to transform the json to base64 string and then JSON.parse(Buffer.from(process.env.CERT, 'base64').toString())对我来说最一致的结果是将 json 转换为 base64 字符串,然后转换为JSON.parse(Buffer.from(process.env.CERT, 'base64').toString())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法解析私钥:错误:无效的 PEM 格式消息 - Failed to parse private key: Error: Invalid PEM formatted message Firebase FCM sendAll() 私钥错误:error:0909006C:PEMroutines:get_name:no start line - Firebase FCM sendAll() private key error: error:0909006C:PEM routines:get_name:no start line GITLAB CI 加载密钥“/dev/fd/63”时出错:格式无效错误:作业失败:退出代码 1 - GITLAB CI Error loading key "/dev/fd/63": invalid format ERROR: Job failed: exit code 1 使用 AWS SDK 为 Java 创建密钥对时创建包含私钥的 file.pem - create a file.pem containing the private key when creating a Key Pair using AWS SDK for Java 从 API 网关客户端证书中检索 PEM 编码的私钥 - Retrieve PEM-encoded private key from API Gateway Client Certificate 生成私钥失败。 请在几分钟后再试一次。 Firebase 不会为项目生成新的私钥 - Failed to generate a private key. Please try again in a few minutes. Firebase doesn't generate new private key for a project 收到此错误 Firebase Error (auth/invalid-api-key) - Getting this error Firebase Error (auth/invalid-api-key) databricks cli in git bash on windows 返回错误消息 invalid parameter - databricks cli in git bash on windows returns error message invalid parameter 无法从 function 源生成清单:错误:服务帐户 object 必须包含字符串“private_key”属性 - Failed to generate manifest from function source: Error: Service account object must contain a string "private_key" property terraform 中的 User_data 无法接收 pem 密钥的变量 - User_data in terraform unable to receive variable of pem key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM