npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aftership/mcrypt

v0.1.3

Published

MCrypt bindings

Downloads

6

Readme

node-mcrypt

MCrypt bindings for Node.js

Install

npm install @aftership/mcrypt

Introduction

Alright! There is already OpenSSL extension bundled with Node.js but there are something wrong with some traditional encryption algorithms on OpenSSL.

I tried to decrypt ciphertext of AES and DES algorithms using OpenSSL but i get the garbage outputs. There are some reasons with OpenSSL like null padding.

Also i saw same issues on the stackoverflow.com. Some people encountered with same problems.

This extension provide the cipher and decipher operations via libmcrypt and compatible with Java Crypto and PHP MCrypt consequently.

You should start with import the package like

var mcrypt = require('mcrypt');

There are 3 exposed common functions in the package. These functions are getAlgorithmNames(), getModeNames() and MCrypt() constructor function. Also there are some functions under the prototype of MCrypt() constructor function.

getAlgorithmNames([path]) : Array

getAlgorithmNames() returns an array that contains available algorithm names. path parameter to specify special algorithm directory. path parameter is not required.

var mcrypt = require('mcrypt');

var algos = mcrypt.getAlgorithmNames();
console.log(algos);

Expected result like that

[ 'cast-128', 'gost', 'rijndael-128', 'twofish', 'arcfour', 'cast-256', 'loki97', 'rijndael-192', 'saferplus', 'wake', 'blowfish-compat', 'des', 'rijndael-256', 'serpent', 'xtea', 'blowfish', 'enigma', 'rc2', 'tripledes' ]

getModeNames([path]) : Array

getModeNames() returns an array that contains available mode names. path parameter to specify special mode directory. path parameter is not required.

var mcrypt = require('mcrypt');

var algos = mcrypt.getModeNames();
console.log(algos);

Expected result like that

[ 'cbc', 'cfb', 'ctr', 'ecb', 'ncfb', 'nofb', 'ofb', 'stream' ]

MCrypt(algorithm, mode [, algorithmDir] [, modeDir]) : Object

MCrypt(algorithm, mode) is a constructor function to create object for cipher and decipher operations. algorithm is a required parameter and one of the values of array returned by getAlgorithmNames(). mode is required parameter and one of the values of array returned by getModeNames(). algorithmDir and modeDir are optional parameters to specify algorithm and mode directories.

var MCrypt = require('mcrypt').MCrypt;

var desEcb = new MCrypt('des', 'ecb');

There are some prototype functions to make cipher decipher operations and to identify algorithm properties.

open(key [, iv])

We are need to open() with a key for decrypt() and encrypt() operations also we should set an iv if required by algorithm in other case iv is optional parameter. key and iv should be string or Buffer

var MCrypt = require('mcrypt').MCrypt;

var desEcb = new MCrypt('des', 'ecb');
desEcb.open('madepass'); // we are set the key

encrypt(plaintext) : Buffer

encrypt() returns a Buffer object that contains ciphertext of plaintext parameter. plaintext parameter should be string or Buffer

var MCrypt = require('mcrypt').MCrypt;

var desEcb = new MCrypt('des', 'ecb');
desEcb.open('madepass'); // we are set the key

var ciphertext = desEcb.encrypt('this is top secret message!');
console.log(ciphertext.toString('base64'));

Expected result like that

fkJnIgtiH8nsGDryyuIsmyf5vABMGStlpACfKCTifvA=

decrypt(ciphertext) : Buffer

decrypt() returns a Buffer object that contains plaintext of ciphertext parameter. ciphertext parameter should be Buffer

var MCrypt = require('mcrypt').MCrypt;

var desEcb = new MCrypt('des', 'ecb');
desEcb.open('madepass'); // we are set the key

var plaintext = desEcb.decrypt(new Buffer('fkJnIgtiH8nsGDryyuIsmyf5vABMGStlpACfKCTifvA=', 'base64'));
console.log(plaintext.toString());

Expected result like that

this is top secret message!

generateIv() : Buffer

generateIv() function generates IV randomly.

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
var iv = blowfishCfb.generateIv();

blowfishCfb.open('somekey', iv);

var ciphertext = blowfishCfb.encrypt('sometext');

console.log(Buffer.concat([iv, ciphertext]).toString('base64'));

validateKeySize(Boolean)

validateKeySize() is a function to disable or enable key size validation on open()

var mc = new MCrypt('blowfish', 'ecb');
mc.validateKeySize(false); // disable key size checking
mc.open('typeconfig.sys^_-');

validateIvSize(Boolean)

validateIvSize() is a function to disable or enable iv size validation on open()

var mc = new MCrypt('rijndael-256', 'cbc');
mc.validateIvSize(false); // disable iv size checking
mc.open('$verysec$retkey$', 'foobar');

selfTest() : Boolean

selfTest() is an utility function to make test algorithm internally and returns boolean value of status

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.selfTest());

isBlockAlgorithmMode() : Boolean

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.isBlockAlgorithmMode());

isBlockAlgorithm() : Boolean

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.isBlockAlgorithm());

isBlockMode() : Boolean

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.isBlockMode());

getBlockSize() : Number

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getBlockSize());

getKeySize() : Number

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getKeySize());

getSupportedKeySizes() : Array

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getSupportedKeySizes());

getIvSize() : Number

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getIvSize());

hasIv() : Boolean

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.hasIv());

getAlgorithmName() : String

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getAlgorithmName());

getModeName() : String

var MCrypt = require('mcrypt').MCrypt;

var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getModeName());