alpha-one
Version:
ideas about recurring tasks in Web- and Backend-Application building
88 lines (46 loc) • 2.19 kB
JavaScript
// Generated by CoffeeScript 1.7.1
(function() {
var BITSNPIECES, TRM, TYPES, alert, badge, bcrypt, chunks, cipher_name, clear_input_route, crypto_input_route, debug, decoder, echo, encoder, help, info, log, njs_crypto, njs_fs, njs_path, password, rpr, text_crypt, warn, whisper;
njs_fs = require('fs');
njs_path = require('path');
TYPES = require('coffeenode-types');
TRM = require('coffeenode-trm');
rpr = TRM.rpr.bind(TRM);
badge = 'encryption';
log = TRM.get_logger('plain', badge);
info = TRM.get_logger('info', badge);
whisper = TRM.get_logger('whisper', badge);
alert = TRM.get_logger('alert', badge);
debug = TRM.get_logger('debug', badge);
warn = TRM.get_logger('warn', badge);
help = TRM.get_logger('help', badge);
echo = TRM.echo.bind(TRM);
BITSNPIECES = require('coffeenode-bitsnpieces');
/*
openssl aes-256-cbc -nosalt -in /Volumes/Storage/temp/cryptotest/text.txt -out /Volumes/Storage/temp/cryptotest/encrypted.txt
^^^^^^^
cf. http://stackoverflow.com/questions/19938470/why-cant-i-decrypt-a-file-with-nodejs-that-i-encrypted-with-openssl
cf. http://stackoverflow.com/a/12378676/893780
NB. NodeJS would appear to have an issue with salts; we should still try to make it work, as it is
considered best practise.
*/
njs_crypto = require('crypto');
cipher_name = 'aes-256-cbc';
password = 'c';
encoder = njs_crypto.createCipher(cipher_name, password);
decoder = njs_crypto.createDecipher(cipher_name, password);
clear_input_route = '/Volumes/Storage/temp/cryptotest/text.txt';
crypto_input_route = '/Volumes/Storage/temp/cryptotest/encrypted.txt';
text_crypt = njs_fs.readFileSync(crypto_input_route);
info(TRM.gold(rpr(text_crypt)));
chunks = [];
chunks.push(decoder.update(text_crypt, 'binary'));
chunks.push(decoder.final('binary'));
info(rpr((chunks.join('')).toString('utf-8')));
bcrypt = require('bcryptjs');
TRM.dir(bcrypt);
text_crypt = njs_fs.readFileSync('/Volumes/Storage/temp/cryptotest/text.txt.bfe');
log(rpr(bcrypt.genSaltSync(0)));
log(rpr(bcrypt.genSaltSync(10)));
log(rpr(bcrypt.genSaltSync()));
}).call(this);