0

I have a requirement where I need to encode data in "iso-8859-1" and then convert back it to readable string in node js.

In .Net env:

string encodedData = "VABpAG0AZQAgAHMAZQByAGUAaQBzAA==";
Encoding encoding = Encoding.GetEncoding("iso-8859-1"); // encoding in "iso-8859-1"
byte[] = decodedbuff = convert.FromBase64String(encodedData);   // getting buffer
result = encoding.GetString(decodedbuff);    //decoding

result = timesereis

In a similar way, I need to encode and decode in node js

In Node js(using iconvlite)

const data = "VABpAG0AZQAgAHMAZQByAGUAaQBzAA=="
const buffer = iconvlite.encode(data,'iso-8859-1');
const result = buffer.toString('utf8');

Here in result, I am getting "VABpAG0AZQAgAHMAZQByAGUAaQBzAA==" instead of decoded result

racras
  • 11
  • 1
  • Does this answer your question? [Convert iso-8859-1 to utf-8 javascript](https://stackoverflow.com/questions/27155419/convert-iso-8859-1-to-utf-8-javascript) – anilcemsimsek May 31 '20 at 11:54
  • No, that one is different, I have to achieve it natively. – racras May 31 '20 at 14:01

1 Answers1

0

By using the following code you get your desired result

let buffer = new Buffer(data, 'base64');
let result = buff.toString('utf-8');

console.log("result: "+text)
TArvela
  • 135
  • 7