Implementation has some flaws
David263 opened this issue · comments
-
The use of fromCharCode() is incorrect. It requires four 16-bit values (Unicode), not four 8-bit values (UTF-8).
-
The algorithms are not compact. For example, here is a more compact base64 encoder:
base64Encode = function(str) {
if (typeof btoa != 'undefined') return btoa(str); // browser
if (typeof Buffer != 'undefined') return new Buffer(str, 'binary').toString('base64'); // Node.js
throw new Error('No Base64 Encode');
};
-
I don't think the use of fromCharCode() is incorrect. Because
btoa
andatob
function use 8-bit binary string, not 16-bit Unicode String. -
This version is compatible with IE6-IE9. If you are only used for IE10+ or other modern browsers, you can use https://github.com/xxtea/xxtea-html5. if you are used for Node.js, you can use https://github.com/xxtea/xxtea-nodejs.