forge
forge copied to clipboard
Invalid PEM when using key stored as string
I'm using a key in two different use cases.
-
It's stored in a file and works normally.
-
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.
same here
Same for me
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