Skip to content

Instantly share code, notes, and snippets.

@jtyberg
Created August 26, 2015 01:22
Show Gist options
  • Save jtyberg/b9cb912dfd986f1cc75e to your computer and use it in GitHub Desktop.
Save jtyberg/b9cb912dfd986f1cc75e to your computer and use it in GitHub Desktop.
openssl encrypt

Encrypts a file using OpenSSL. Requires ENC_PASS set and INSECURE pointing to the absolute path of the insecure file to encrypt.

#!/bin/bash
if [ -z "$ENC_PASS" ]; then
echo "ENC_PASS not set"
exit 1
fi
if [ ! -f "$INSECURE" ]; then
echo "INSECURE file not set/found"
exit 1
fi
salt=$(openssl dgst -hmac "$INSECURE:$ENC_PASS" -sha256 "$INSECURE" | tail -c 16)
openssl enc -aes-256-cbc -pass env:ENC_PASS -e -a -S $salt -in "$INSECURE" -out "$INSECURE.secure"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment