It is about the International Data Encryption Algorithm, a.k.a IDEA cypher which is implemented in JavaScript within ~10 KiB. If you want better compatibility, you may need the polyfill version dist/idea.all.js
, which has shimmed Int8Array
for you.
- IE6+ (polyfills required for ES7- browsers)
- NodeJS
npm install @aleen42/idea
-
without padding:
function paddingToBytes(str) { typeof str !== 'string' && (str = JSON.stringify(str)); const blockSize = 8; const srcBytes = encoder.encode(str); const len = Math.ceil(srcBytes.length / blockSize) * blockSize; // padding with \x00 const src = new Int8Array(len); src.set(srcBytes); return src; } const IDEA = require('@coremail/idea'); const idea = new IDEA(str2bytes('private key'), /* no padding */-1); idea.encrypt(paddingToBytes('message')); // => Int8Array[]
-
with xor padding (ENC3 by default):
const encoder = new TextEncoder(); const IDEA = require('@coremail/idea'); const idea = new IDEA(str2bytes('private key'), /* ENC3 by default */197); idea.encrypt(encoder.encode('message')); // => Int8Array[]
- ==================== 1.0.0 Initial release ====================
Have an idea? Found a bug? See how to contribute.
MIT © aleen42