Decrypt Base64 Array in nodejs

1

Hi, I have an encrypted fix in base64 and when I decrypt it, it does it with characters that I would like to delete:

  const b64_to_utf8 = (str) => {                           
      return new Buffer(str, 'base64').toString('ascii')   
  }

Deciphered looks like this:

Is it possible to remove the characters?

try a .split('\n'); but it did not work.

    
asked by Hernan Humaña 20.08.2018 в 04:52
source

1 answer

2

I have solved it!

Basically the characters were generated because at no time did it transform it to what was really a json , if not rather it remained a string. on the other hand I also influenced the code of% ascii which did not allow to transform it to JSON generating the error

  

SyntaxError: Unexpected token n in JSON at position 782

by changing it to the encoding format utf-8 allowed parsing the string and transforms it to JSON .

As a final result the code would be as follows:

let Mybase64 = '//*...*//'

const b64_to_utf8 = str => JSON.parse(new Buffer(str,'base64').toString('utf-8'));

b64_to_utf8(Mybase64);
// return JSON
    
answered by 20.08.2018 в 07:00