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

2
  • Does this answer your question? Convert iso-8859-1 to utf-8 javascript Commented May 31, 2020 at 11:54
  • No, that one is different, I have to achieve it natively. Commented May 31, 2020 at 14:01

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.