Is private key suppose to include the \n in it?
Asked Answered
I

1

6

I create a json key file for my GCP service account, since it's in JSON, it comes in this format:

{
  "type": "service_account",
  "project_id": "my-project",
  "private_key_id": "abcde",
  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCwrTSu4RbY2I1C\nBaLF7coPwrYBjPCz+p+r1toO3fhVbWh+IWFe0H0wDs8gGe1XUSzbE/ZxlKt5k2jz\n3qoIbPjK/UqM3JlEpwlwDmIzEQuArLMsiZ9hjIEkDn3WbUnYf8SZu4tSFNLLyYcb\nnl...",
   ...
}

I am trying to insert it into a 3rd party software that uses it, but it keep giving me key error. I am wondering if it's because the \n inside the private key is json format artifact and should be removed?

Also should I remove the -----BEGIN PRIVATE KEY----- part? Is that also json format artifact?

Immix answered 22/4, 2022 at 17:2 Comment(3)
giving me key error is not a good problem description. The \n is within the JSON key value, so it does not affect the JSON. Do not remove the BEGIN PRIVATE KEY as that string is part of the key format (PKCS-8) which is a PEM Base64 encoded binary value. Edit your question with the problem you have importing the key. Most likely the software is expecting a different format. Look up which format they require.Oberland
The format "-----BEGIN PRIVATE KEY-----\n[PRIVATE-KEY]\n-----END PRIVATE KEY-----\n" is part of the JSON Key format, and you shouldn't remove it from your Key. Please share more information about the 3rd party software that you are using and details about the key error that you state in your post.Amentia
I am also getting errors regarding the \n on a Linux machine. Did you find out the solution?Benitez
S
-1

Actually try removing the line breaks \n in JSON, i.e. format as text, works for me ...

So instead of just one long line ...

-----BEGIN PRIVATE KEY-----MII...Evg-----END PRIVATE KEY-----

Insert key this way

-----BEGIN PRIVATE KEY----- MII...Evg ......... ......... etc -----END PRIVATE KEY-----

Silkaline answered 5/9, 2024 at 8:12 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Farad

© 2022 - 2025 — McMap. All rights reserved.