Skip to content

Instantly share code, notes, and snippets.

@petehamilton
Last active March 5, 2016 09:26
Show Gist options
  • Select an option

  • Save petehamilton/e97004e84e5f29519a91 to your computer and use it in GitHub Desktop.

Select an option

Save petehamilton/e97004e84e5f29519a91 to your computer and use it in GitHub Desktop.

Revisions

  1. petehamilton revised this gist Nov 3, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions openssl-encrypt.sh
    Original file line number Diff line number Diff line change
    @@ -33,5 +33,5 @@ openssl enc -aes-256-cbc -salt -in $CSV_FILE -out $CSV_FILE_ENCRYPTED -pass file
    echo 'Decrypting key'
    openssl rsautl -decrypt -inkey $PRIVATE_KEY -in KEY_FILE_ENCRYPTED -out $KEY_FILE

    echo 'Can decrypt manually with:'
    echo "openssl enc -d -aes-256-cbc -in ${CSV_FILE_ENCRYPTED} -out output.txt -pass file:${KEY_FILE}"
    echo 'Decrypting file'
    openssl enc -d -aes-256-cbc -in $CSV_FILE_ENCRYPTED -out output.txt -pass file:$KEY_FILE
  2. petehamilton revised this gist Nov 3, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions openssl-encrypt.sh
    Original file line number Diff line number Diff line change
    @@ -22,16 +22,16 @@ openssl rand 256 > $KEY_FILE
    echo 'Generating public key'
    openssl rsa -in $PRIVATE_KEY -passin file:$PASSWORD_FILE -pubout -outform pem > $PUBLIC_KEY

    # echo 'Encrypting the random key'
    # openssl rsautl -encrypt -inkey $PUBLIC_KEY -pubin -in $KEY_FILE -out $KEY_FILE_ENCRYPTED
    echo 'Encrypting the random key'
    openssl rsautl -encrypt -inkey $PUBLIC_KEY -pubin -in $KEY_FILE -out $KEY_FILE_ENCRYPTED

    echo 'Encrypting CSV file'
    openssl enc -aes-256-cbc -salt -in $CSV_FILE -out $CSV_FILE_ENCRYPTED -pass file:$KEY_FILE

    # Send encrypted file and key across network

    # echo 'Decrypting key'
    # openssl rsautl -decrypt -inkey $PRIVATE_KEY -in KEY_FILE_ENCRYPTED -out $KEY_FILE
    echo 'Decrypting key'
    openssl rsautl -decrypt -inkey $PRIVATE_KEY -in KEY_FILE_ENCRYPTED -out $KEY_FILE

    echo 'Can decrypt manually with:'
    echo "openssl enc -d -aes-256-cbc -in ${CSV_FILE_ENCRYPTED} -out output.txt -pass file:${KEY_FILE}"
  3. petehamilton created this gist Nov 3, 2014.
    37 changes: 37 additions & 0 deletions openssl-encrypt.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #! /usr/bin/env bash

    set -e
    set -u

    PRIVATE_KEY='private-key.pem'
    PUBLIC_KEY='public-key.pem'
    KEY_FILE="key.bin"
    KEY_FILE_ENCRYPTED="key.bin.enc"
    CSV_FILE='fixture-secret.txt'
    CSV_FILE_ENCRYPTED='secret.txt.enc'
    PASSWORD_FILE='password.txt'

    echo "!!! ALL PASSWORDS ARE $(cat $PASSWORD_FILE) !!!"

    echo 'Generating RSA key'
    openssl genrsa -aes256 -out $PRIVATE_KEY -passout file:$PASSWORD_FILE 4096

    echo 'Generating 256 bit random key'
    openssl rand 256 > $KEY_FILE

    echo 'Generating public key'
    openssl rsa -in $PRIVATE_KEY -passin file:$PASSWORD_FILE -pubout -outform pem > $PUBLIC_KEY

    # echo 'Encrypting the random key'
    # openssl rsautl -encrypt -inkey $PUBLIC_KEY -pubin -in $KEY_FILE -out $KEY_FILE_ENCRYPTED

    echo 'Encrypting CSV file'
    openssl enc -aes-256-cbc -salt -in $CSV_FILE -out $CSV_FILE_ENCRYPTED -pass file:$KEY_FILE

    # Send encrypted file and key across network

    # echo 'Decrypting key'
    # openssl rsautl -decrypt -inkey $PRIVATE_KEY -in KEY_FILE_ENCRYPTED -out $KEY_FILE

    echo 'Can decrypt manually with:'
    echo "openssl enc -d -aes-256-cbc -in ${CSV_FILE_ENCRYPTED} -out output.txt -pass file:${KEY_FILE}"