[Node.js Home][Home]
Node.js integrates cryptography with the crypto library. This example implements RC4, and which is a variable length key cipher:
Node.js Crypto (RC4)
[Node.js Home][Home]
Node.js integrates cryptography with the crypto library. This example implements RC4, and which is a variable length key cipher:
|
A sample run is:
Message: test Passphrase: test Ciphertext: 83d2e09c Decipher: test
The following is some sample code
// RC4 var crypto = require('crypto'); var keyname="test"; var plaintext = "testing"; var args = process.argv; if (args.length>1) plaintext=args[2]; if (args.length>2) keyname=args[3]; var key = crypto.createHash('sha256').update(keyname).digest(); var cipher = crypto.createCipheriv('rc4', key,'' ); var ciphertext = cipher.update( plaintext, 'utf8', 'hex'); console.log("Ciphertext:\t",ciphertext); var decipher = crypto.createDecipheriv('rc4', key,'' ); var text = decipher.update( ciphertext, 'hex','utf8'); console.log("Decipher:\t",text);
For a password of "napier, a range of fruits have been ciphered using the RC4 cipher stream:
8d1cc8bdf6da 911adbb2e6dda57cdaad 8907deba
Answer these: