I forgot where I found this one but this custom made function to convert string to bytes worked when I used it in my code.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
function stringToBytes(str) { var ch, st, re = []; for (var i = 0; i < str.length; i++ ) { ch = str.charCodeAt(i); // get char st = []; // set up "stack" do { st.push( ch & 0xFF ); // push byte to stack ch = ch >> 8; // shift value down by 1 byte } while ( ch ); // add stack contents to result // done because chars have "wrong" endianness re = re.concat( st.reverse() ); } // return an array of bytes return re; }, |