Encrypts a file using OpenSSL. Requires ENC_PASS set and INSECURE pointing to the absolute path of the insecure file to encrypt.
Created
August 26, 2015 01:22
-
-
Save jtyberg/b9cb912dfd986f1cc75e to your computer and use it in GitHub Desktop.
openssl encrypt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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