1.0.8 • Published 6 years ago

fdoering-mcrypt v1.0.8

Weekly downloads
43
License
ISC
Repository
github
Last release
6 years ago

fdoering-mcrypt

NodeJS module - migrated mcrypt.js from F. Doering jsmcrypt Version 0.1 (https://code.google.com/archive/p/js-mcrypt/).

jsmcrypt version 0.1 - Copyright 2012 F. Doering

Install with npm

npm install fdoering-mcrypt

NodeJS Encrypt Example

// Require
var mcrypt = require("fdoering-mcrypt");

// Pseudo key **DO NOT USE THIS**
var key = "12345678901234567890123456789012";
// Pseudo initialization vector (iv)
var iv = "abcdefghijklmnopqrstuv1234567890";

// Plaintext
var message = "Hello there!";

// Encrypt
var encrypted_binary = mcrypt.Encrypt(message, iv, key, "rijndael-256", "cbc");

// Convert to Base64 for transporting using Node.js native Buffer class.
var encrypted_base64 = Buffer.from(encrypted_binary, "binary").toString("base64");

NodeJS Decrypt Example

// Convert Base64 back to Binary
var encrypted_binary = Buffer.from(encrypted_base64, "base64").toString("binary");

// Decrypt
var plaintext = mcrypt.Decrypt(encrypted_binary, iv, key, "rijndael-256", "cbc");

// Remove padding
plaintext = plaintext.replace(/\0/g,'');

// Prints "Hello there!"
console.log(plaintext);
1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago