xxtea / xxtea-js

XXTEA for encryption algorithm library JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implementation has some flaws

David263 opened this issue · comments

  1. The use of fromCharCode() is incorrect. It requires four 16-bit values (Unicode), not four 8-bit values (UTF-8).

  2. 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');
};

  1. I don't think the use of fromCharCode() is incorrect. Because btoa and atob function use 8-bit binary string, not 16-bit Unicode String.

  2. 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.