Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSA key in env causing errors

Using this library.. https://github.com/motdotla/dotenv

I've added a private RSA key to .env. Using it to sign a JWT. When I sign the JWT, this error greats me.

error:0906D066:PEM routines:PEM_read_bio:bad end line

My RSA key is just a basic multi line, key.

-----BEGIN RSA PRIVATE KEY-----
MIIEpgIBAAKCAQE.......
........

The RSA key is multi-line. DotEnv can only read one-liners, the unfortunate work around (AFIAK) are to add a \n to the end of every line. And then make this string a one liner. But this error keeps occuring..

Has anyone else experienced this and have solution? Or perhaps know of another env file manager that can handle multi-lines?

like image 469
GN. Avatar asked Aug 10 '26 15:08

GN.


1 Answers

Add surrounding double quotes to the value in the .env file and replace line breaks with \n like so:

KEY="-----BEGIN RSA PRIVATE KEY-----\nMIIE..."
like image 146
Shant Marouti Avatar answered Aug 13 '26 07:08

Shant Marouti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!