forge icon indicating copy to clipboard operation
forge copied to clipboard

Invalid PEM when using key stored as string

Open omaralqady opened this issue 7 years ago • 3 comments

I'm using a key in two different use cases.

  1. It's stored in a file and works normally.

  2. It's added by the user as a string, and this case when running: forge.pki.decryptRsaPrivateKey( keyStr, "passphrase") fails with an error: "Invalid PEM formatted message".

I know that the file would have a header or something like that attached to it, but should that matter?

The text content of the key's file and keyStr are exactly the same, so I must be missing something.

I would appreciate your help with this.

omaralqady avatar Mar 01 '17 17:03 omaralqady

same here

grgmo avatar Jun 24 '17 17:06 grgmo

Same for me

hacaro76 avatar Jun 01 '22 06:06 hacaro76

I find my self with this issue the problem: PEM traditionally uses line breaks every 64 characters in Base64 encoded content. While many libraries can handle Base64 content that does not follow this convention, some may expect or require these line breaks. This is really the problem with forge you need to take this line break every 64 characters to make forge able to deal with this, this is possible in js with this const base64Lines = base64Key.match(/.{1,64}/g).join("\n"). Hope this will be helpfull for you as it did for me

jlozanoher94 avatar Nov 01 '23 02:11 jlozanoher94