package
JavaScript implementations of network transports, cryptography, ciphers, PKI, message digests, and various utilities.
npm install node-tlsGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
1.6 MB
Includes dependencies.
A native implementation of [TLS][] (and various other cryptographic tools) in [JavaScript][].
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.
If you want to use forge with [Node.js][], it is available through npm:
Installation:
npm install node-tlsYou can then use forge as a regular module:
const { tls } = require('node-tls');The npm package includes pre-built min.js, all.min.js, and
prime.worker.min.js using the [UMD][] format.
Using forge in Node.js to match openssl's "enc" command line tool (Note: OpenSSL "enc" uses a non-standard file format with a custom key derivation function and a fixed iteration count of 1, which some consider less secure than alternatives such as OpenPGP/GnuPG):
var forge = require('node-tls');
var fs = require('fs');
// openssl enc -des3 -in input.txt -out input.enc
function 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.txt
function 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'});
}Provides [AES][] encryption and decryption in [CBC][], [CFB][], [OFB][], [CTR][], and [GCM][] modes. See CIPHER for examples.
Provides [3DES][] and [DES][] encryption and decryption in [ECB][] and [CBC][] modes. See CIPHER for examples.
This is a fork from node-forge project and license under LICENSE