alpha-one
Version:
ideas about recurring tasks in Web- and Backend-Application building
82 lines (55 loc) • 2.77 kB
text/coffeescript
############################################################################################################
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'
# log TRM.green BITSNPIECES.get_filtered_caller_routes()
# # OSENV = require 'osenv'
# # info name, OSENV[ name ]() for name of OSENV
# # CRYPT = require 'file-encryptor'
# # key = 'c'
# # options =
# # 'algorithm': 'aes-128-cbc'
# # CRYPT.decryptFile '/tmp/text.crypt', '/tmp/output_file.txt', key, options, ( error ) ->
# # throw error if error?
###
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 #, encoding: 'hex'
info TRM.gold rpr text_crypt
# text_crypt = encoder.update text, 'utf8', 'hex'
# text_crypt += encoder.final 'hex'
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' #, encoding: 'ascii'
log rpr bcrypt.genSaltSync 0
log rpr bcrypt.genSaltSync 10
log rpr bcrypt.genSaltSync()