A native implementation of [TLS][] (and various other cryptographic tools) in
[JavaScript][].
Introduction
The node-tls software is a fully native implementation of the [TLS][] protocol
in JavaScript, a set of cryptography utilities, and a set of tools for
developing Web Apps that utilize many network resources.
Installation
Node.js
If you want to use forge with [Node.js][], it is available through npm:
var forge = require('node-tls');var fs = require('fs');// openssl enc -des3 -in input.txt -out input.encfunction encrypt(password) { var input = fs.readFileSync('input.txt', {encoding: 'binary'}); // 3DES key and IV sizes var keySize = 24; var ivSize = 8; // get derived bytes // Notes: // 1. If using an alternative hash (eg: "-md sha1") pass // "md.sha1.create()" as the final parameter. // 2. If using "-nosalt", set salt to null. var salt = random.getBytesSync(8); // var md = md.sha1.create(); // "-md sha1" var derivedBytes = pbe.opensslDeriveBytes( password, salt, keySize + ivSize/*, md*/); var buffer = util.createBuffer(derivedBytes); var key = buffer.getBytes(keySize); var iv = buffer.getBytes(ivSize); var cipher = cipher.createCipher('3DES-CBC', key); cipher.start({iv: iv}); cipher.update(util.createBuffer(input, 'binary')); cipher.finish(); var output = util.createBuffer(); // if using a salt, prepend this to the output: if(salt !== null) { output.putBytes('Salted__'); // (add to match openssl tool output) output.putBytes(salt); } output.putBuffer(cipher.output); fs.writeFileSync('input.enc', output.getBytes(), {encoding: 'binary'});}// openssl enc -d -des3 -in input.enc -out input.dec.txtfunction decrypt(password) { var input = fs.readFileSync('input.enc', {encoding: 'binary'}); // parse salt from input input = util.createBuffer(input, 'binary'); // skip "Salted__" (if known to be present) input.getBytes('Salted__'.length); // read 8-byte salt var salt = input.getBytes(8); // Note: if using "-nosalt", skip above parsing and use // var salt = null; // 3DES key and IV sizes var keySize = 24; var ivSize = 8; var derivedBytes = pbe.opensslDeriveBytes( password, salt, keySize + ivSize); var buffer = util.createBuffer(derivedBytes); var key = buffer.getBytes(keySize); var iv = buffer.getBytes(ivSize); var decipher = cipher.createDecipher('3DES-CBC', key); decipher.start({iv: iv}); decipher.update(input); var result = decipher.finish(); // check 'result' for true/false fs.writeFileSync( 'input.dec.txt', decipher.output.getBytes(), {encoding: 'binary'});}