Skip to content

Instantly share code, notes, and snippets.

@GeoffreyHervet
Created August 12, 2019 15:01
Show Gist options
  • Select an option

  • Save GeoffreyHervet/9f0a687e8ad8ab2325e58a685b0e6c8e to your computer and use it in GitHub Desktop.

Select an option

Save GeoffreyHervet/9f0a687e8ad8ab2325e58a685b0e6c8e to your computer and use it in GitHub Desktop.

Revisions

  1. @bbstilson bbstilson revised this gist Apr 20, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions encrypt.js
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@ const path = require('path');
    const zlib = require('zlib');

    const AppendInitVect = require('./appendInitVect');
    const getCipherKey = require('./getCipherKey');

    function encrypt({ file, password }) {
    // Generate a secure, pseudo random initialization vector.
  2. @bbstilson bbstilson renamed this gist Apr 20, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @bbstilson bbstilson revised this gist Apr 20, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion encrypt_complete.js
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ function encrypt({ file, password }) {
    const CIPHER_KEY = getCipherKey(password);
    const readStream = fs.createReadStream(file);
    const gzip = zlib.createGzip();
    const cipher = crypto.createCipheriv(aes256, CIPHER_KEY, initVect);
    const cipher = crypto.createCipheriv('aes256', CIPHER_KEY, initVect);
    const appendInitVect = new AppendInitVect(initVect);
    // Create a write stream with a different file extension.
    const writeStream = fs.createWriteStream(path.join(file + ".enc"));
  4. @bbstilson bbstilson revised this gist Apr 20, 2018. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions encrypt_complete.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    const crypto = require('crypto');
    const fs = require('fs');
    const path = require('path');
    const zlib = require('zlib');

    const AppendInitVect = require('./appendInitVect');

    function encrypt({ file, password }) {
    // Generate a secure, pseudo random initialization vector.
    const initVect = crypto.randomBytes(16);
  5. @bbstilson bbstilson revised this gist Apr 20, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions encrypt_complete.js
    Original file line number Diff line number Diff line change
    @@ -4,12 +4,12 @@ function encrypt({ file, password }) {

    // Generate a cipher key from the password.
    const CIPHER_KEY = getCipherKey(password);
    const readStream = fs.createReadStream(file);
    const readStream = fs.createReadStream(file);
    const gzip = zlib.createGzip();
    const cipher = crypto.createCipheriv(‘aes256’, CIPHER_KEY, initVect);
    const appendInitVect = new AppendInitVect(initVect);
    // Create a write stream with a different file extension.
    const writeStream = fs.createWriteStream(path.join(file + .enc));
    // Create a write stream with a different file extension.
    const writeStream = fs.createWriteStream(path.join(file + ".enc"));

    readStream
    .pipe(gzip)
  6. @bbstilson bbstilson created this gist Apr 20, 2018.
    19 changes: 19 additions & 0 deletions encrypt_complete.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    function encrypt({ file, password }) {
    // Generate a secure, pseudo random initialization vector.
    const initVect = crypto.randomBytes(16);

    // Generate a cipher key from the password.
    const CIPHER_KEY = getCipherKey(password);
    const readStream = fs.createReadStream(file);
    const gzip = zlib.createGzip();
    const cipher = crypto.createCipheriv(‘aes256’, CIPHER_KEY, initVect);
    const appendInitVect = new AppendInitVect(initVect);
    // Create a write stream with a different file extension.
    const writeStream = fs.createWriteStream(path.join(file + .enc’));

    readStream
    .pipe(gzip)
    .pipe(cipher)
    .pipe(appendInitVect)
    .pipe(writeStream);
    }