Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of Buffer().toString()

I have inherited a project and there is a .cert value which I am trying to reverse engineer to see how it was created. This value is created like so:

var rawCertValue = 'Q2VydGlmaWNhdGU6DQogICAgRG......'; // long value
var certificate = new Buffer(rawCertValue, 'base64').toString();

I have the original .pem key and can see that the certificate value in there matches the certificate variable that is generated above. What I am trying to figure out is how they got the rawCertValue

I guess my question is what would be the reverse function for:

new Buffer(rawCertValue, 'base64').toString();
like image 609
red house 87 Avatar asked Sep 13 '25 16:09

red house 87


1 Answers

That new Buffer variant is deprecated, you should use Buffer.from instead which lets you specify the encoding. Also the toString method takes an optional encoding, which defaults to utf8. So your original code is equivalent to

var certificate = Buffer.from(rawCertValue, 'base64').toString('utf8');

The reverse operation for that would then be

var rawCertValue = Buffer.from(certificate, 'utf8').toString('base64');
like image 96
Bergi Avatar answered Sep 16 '25 06:09

Bergi