I know there are a bunch of similar questions here but after hours of reading I cannot find a solution to mine. So:
I am trying to use jwk-to-pem for signing a JSON web token using jsonwebtoken . I have previously achieved this but now the same code does not work. After calling jwt.sign
with the generated pem
I get error:0906D06C:PEM routines:PEM_read_bio:no start line
. I know that common reasons would include wrong linebreaks like \\r
or generally wrong format. I actually even dug through the core nodejs code and found the line throwing this error.
Countless adjustments and attempts brought no solution. Specifically:
\\n
-----BEGIN PUBLIC KEY-----
or -----BEGIN RSA PUBLIC KEY-----
\\n
as last character pem
string to disk and re-reading it, using node's fs
. pem
file to several other files with several editors eg using vi -b
or regex. pem
content to jwt.sign
as well as pem.toString('utf8')
as well as every other string encouding supported by node pem
file using linux tools and give that to jwt.sign
. Specifically: ssh-keygen -t rsa -b 2048 -f jwtRS256.key
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.pem
What am I missing here? What possible causes I did not think of can this have?
I found a very simple explanation: I was by mistake using the public instead of the private key. The error thrown by openssl/crypto is very misleading.
Using a private pem/key the signing works as expected.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.