I have this string in java:
"test.message"
byte[] bytes = plaintext.getBytes("UTF-8");
//result: [116, 101, 115, 116, 46, 109, 101, 115, 115, 97, 103, 101]
If I do the same thing in javascript:
stringToByteArray: function (str) {
str = unescape(encodeURIComponent(str));
var bytes = new Array(str.length);
for (var i = 0; i < str.length; ++i)
bytes[i] = str.charCodeAt(i);
return bytes;
},
I get:
[7,163,140,72,178,72,244,241,149,43,67,124]
I was under the impression that the unescape(encodeURIComponent()) would correctly translate the string to UTF-8. Is this not the case?
Reference:
http://ecmanaut.blogspot.be/2006/07/encoding-decoding-utf8-in-javascript.html