How to create pem key in string format with base64 encoded key

I am trying to create a pem key from the ecdsa private key, I have to use the pem string in another function to create the JWT, but when I try

var base64key = 'MDc4M2UwODJiNmFhMmVmOWIxZDdjN2YwMTYxMGM4M2ZkZTk2OTE3OWVlNzdlYzBmNTJmY2NiNjBhMDBjNTA0OQ=='; var privKey64 = '-----BEGIN PRIVATE KEY-----\n'+base64key+'\n-----END PRIVATE KEY-----'; var sJWS = KJUR.jws.JWS.sign(null, {alg: "ES256"}, privKey64);

So, when I try to pass this pem key to sign the function, I get the following error

* init failed: invalid PKCS8 private key

Therefore, I suspect that the generated pem key does not have a valid format

+1
source share

Source: https://habr.com/ru/post/885411/


All Articles