Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

encryption-for-node

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encryption-for-node

Portable Crypto libraries for Node and Browsers

  • 1.1.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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.

Keywords

FAQs

Package last updated on 25 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc