SimpleRC4
import
Use
var RC4 = ;
to import the package.
basic usage
The constructor call
var 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 Buffer
s and the encrypted message is given as return value.
simple example
var key = 1 2 3 4;var msg = 'secret message';console; // create encryption instancevar enc = key;enc;console; // create decryption instance (equals encryption instance)var dec = key;dec;console;
encryption and decryption of streams
You can use RC4.Transform to encrypt a readable stream as follows:
var fIn = fs fOut = fs; var transform = "abcd";fIn;transform;
The same procedure can be used to decrypt a given stream:
var fIn = fs fOut = fs; var transform = "abcd";fIn;transform;