1.1.7 • Published 5 months ago

encryption-for-node v1.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

encryption-for-node

14 vanilla TypeScript, 0 dependencies portable encryption libraries. Great for Node servers or Browsers.

Encryptions

  • AES
  • Aria
  • Blowfish
  • Camellia
  • Cast128
  • ChaCha20
  • Triple DES
  • IDEA
  • MARS
  • MISTY1
  • SEED
  • Serpent
  • SM4
  • Twofish

Installation

npm install encryption-for-node

Features

  • Barebones, small size, no bulk encryption methods.
  • Runs ECB or CBC modes.
  • Static or PKCS padding.
  • Accepts Buffer or Uint8Array. Returns the same type.
  • Easily modifiable to fit any needs.

Require or Import

//For Node:
const {CAST128} = require('encryption-for-node');
//For Browser:
import {CAST128} from 'encryption-for-node';

Use

All encryptions classes follow the same format. Use cipher.set_key then cipher.set_iv for CBC mode. If cipher.set_iv is not set, runs in ECB mode. If static padding number is not set, uses PKCS padding on last block if needed.

//encrypt:
const cipher = new Blowfish();
cipher.set_key(Uint8ArrayOrBufferKey);
cipher.set_iv(Uint8ArrayOrBufferIV);
var paddingNumber = 0xFF; //If padding number is not set, uses PKCS padding.
const CipherText = cipher.encrypt(Uint8ArrayOrBufferText, paddingNumber);
//decrypt
const cipher = new Blowfish();
cipher.set_key(Uint8ArrayOrBufferKey);
cipher.set_iv(Uint8ArrayOrBufferIV);
var paddingNumberOrTrue = 0xFF; //Will check the last block and remove if padded is ``number``. Will remove PKCS if ``true``.
const DecryptedUInt8ArrayOrBuffer = cipher.decrypt(ciphertext, paddingNumberOrTrue);

Note: Most encryptions can be run multiple times once setup with a key. IV will need to be reset for CBC mode before each use.

Tech

EncryptionKey LengthIV Length
AES16, 24 or 32 byte key16 byte IV
ARIA16, 24 or 32 byte keysame as key
BLOWFISHUp to 56 byte key8 byte IV
CAMELLIA16, 24 or 32 byte key16 byte IV
CAST12816 byte key8 byte IV
*CHACHA2032 byte key, 12 byte nonce16 byte IV
DES38 byte key8 byte IV
IDEA16 byte key8 byte IV
MARS16, 24 or 32 byte key16 byte IV
MISTY116 byte key8 byte IV
SEED16 byte key16 byte IV
SERPENT16, 24 or 32 byte key16 byte IV
SM416 byte key16 byte IV
TWOFISH16 byte key16 byte IV

*key must be reset after each use

License

MIT

Disclaimer

This library spawned from a project where issues with different Node versions meant not having the same access to some of these encryptions. I created these vanilla JavaScript versions of these encryptions so we could implement them in different environments and have them all match. I do not know how they hold up speed or performance wise against something more direct like a C++ source code, as the goal here was flexible. Some encryptions were limited in key length as it would have required extra coding outside of the function of the project. All libraries are presented as is, I take no responsibility for outside use.

If you plan to implement these encryption libraries for anything other than personal or educational use, please be sure you have the appropriate permissions from the original owner of the cipher.

1.1.7

5 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

7 months ago

1.1.1

11 months ago

1.1.0

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago