New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

simple-rc4

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-rc4

A pure JavaScript implementation of RC4 stream en/decryption

latest
npmnpm
Version
0.0.1-b
Version published
Weekly downloads
42
-31.15%
Maintainers
1
Weekly downloads
 
Created
Source

SimpleRC4

import

Use

var RC4 = require('simple-rc4');

to import the package.

basic usage

The constructor call

var rc4 = new RC4(key)

creates a new encryption/decryption instance. Here key should be a variable of type Buffer or String. Subsequential calls to rc4.update(msg) encrypt the given argument. If msg is a Buffer it will be encrypted in place. Messages of type String are converted to Buffers and the encrypted message is given as return value.

simple example

var key = new Buffer([1, 2, 3, 4]);
var msg = new Buffer('secret message');
console.log('input:     ', msg.toString(), ' == ', msg.toString('hex'));

// create encryption instance
var enc = new RC4(key);
enc.update(msg);
console.log('encrypted: ', msg.toString(), ' == ', msg.toString('hex'));

// create decryption instance (equals encryption instance)
var dec = new RC4(key);
dec.update(msg);
console.log('output:    ', msg.toString(), ' == ', msg.toString('hex'));

encryption and decryption of streams

You can use RC4.Transform to encrypt a readable stream as follows:

var fIn = fs.createReadStream('message.txt'),
    fOut = fs.createWriteStream('encrypted_message.txt');

var transform = new RC4.Transform("abcd");
fIn.pipe(transform);
transform.pipe(fOut);

The same procedure can be used to decrypt a given stream:

var fIn = fs.createReadStream('encrypted_message.txt'),
    fOut = fs.createWriteStream('decrypted_message.txt');

var transform = new RC4.Transform("abcd");
fIn.pipe(transform);
transform.pipe(fOut);

Keywords

crypto

FAQs

Package last updated on 13 Jun 2015

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