lcobucci / jwt

A simple library to work with JSON Web Token and JSON Web Signature
https://lcobucci-jwt.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
7.31k stars 601 forks source link

Impossible to parse private key #1037

Closed celian-hamon closed 1 year ago

celian-hamon commented 1 year ago
    It was not possible to parse your key, reason:
    * error:0909006C:PEM routines:get_name:no start line
    * error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
    * error:23077074:PKCS12 routines:PKCS12_pbe_crypt:pkcs12 cipherfinal error
    * error:2306A075:PKCS12 routines:PKCS12_item_decrypt_d2i:pkcs12 pbe crypt error
    * error:0907B00D:PEM routines:PEM_read_bio_PrivateKey:ASN1 lib

i have a private key in a .env but it cant be read

arguments: { $pem: """ -----BEGIN ENCRYPTED PRIVATE KEY----- zedqzdqzdzdqzqd...... -----END ENCRYPTED PRIVATE KEY----- """

SvenRtbg commented 1 year ago

The internally used OpenSSL extension is really picky about the format (and maybe this is for a very good reason): You require a newline after the "---BEGIN ENCRYPTED PRIVATE KEY---" header line and before the "---END ENCRYPTED PRIVATE KEY ---" line. If the newline isn't present in your env data, add it. Surprisingly the binary data between these two lines may contain any number of newlines, including zero.

celian-hamon commented 1 year ago

Thanks for your help, i found my issue my key was encrypted, so i decrypted it worked sorry for the useless issue :/