I want my code to extract private key from my pem file .
My pem file looks like this -> —–BEGIN RSA PRIVATE KEY—– some encrypted code —–END RSA PRIVATE KEY—– .
I have the same code in ruby but i’m not able to do this in javascript.
Advertisement
Answer
JavaScript
x
6
1
const fs = require("fs");
2
3
var myKey = fs.readFileSync("mykey.pem", "utf8").replace("-----BEGIN RSA PRIVATE KEY-----", "").replace("-----END RSA PRIVATE KEY-----", "").trim();
4
5
console.log("My key is: ", myKey);
6
Keep in mind, this will only work if there is one key in the file instead of a list of keys, but you should get the gist.