
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
This repository not in active maintain state. Please use cryptian library instead of this library.
MCrypt bindings for Node.js
npm install mcrypt
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()
returns an array that contains available algorithm names.
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()
returns an array that contains available mode names.
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)
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()
.
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.
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()
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()
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()
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()
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()
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()
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());
var MCrypt = require('mcrypt').MCrypt;
var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.isBlockAlgorithmMode());
var MCrypt = require('mcrypt').MCrypt;
var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.isBlockAlgorithm());
var MCrypt = require('mcrypt').MCrypt;
var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.isBlockMode());
var MCrypt = require('mcrypt').MCrypt;
var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getBlockSize());
var MCrypt = require('mcrypt').MCrypt;
var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getKeySize());
var MCrypt = require('mcrypt').MCrypt;
var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getSupportedKeySizes());
var MCrypt = require('mcrypt').MCrypt;
var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getIvSize());
var MCrypt = require('mcrypt').MCrypt;
var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.hasIv());
var MCrypt = require('mcrypt').MCrypt;
var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getAlgorithmName());
var MCrypt = require('mcrypt').MCrypt;
var blowfishCfb = new MCrypt('blowfish', 'cfb');
console.log(blowfishCfb.getModeName());
FAQs
MCrypt bindings
The npm package mcrypt receives a total of 12,265 weekly downloads. As such, mcrypt popularity was classified as popular.
We found that mcrypt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.