Skip to content

Instantly share code, notes, and snippets.

@giner
Last active May 15, 2023 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giner/fd417991d6ba457900c5f63fa39d4fb7 to your computer and use it in GitHub Desktop.
Save giner/fd417991d6ba457900c5f63fa39d4fb7 to your computer and use it in GitHub Desktop.
Encrypt / Decrypt files with OpenSSL
#!/bin/bash
# Inspired by https://www.meixler-tech.com/web-browser-based-file-encryption-decryption.html
set -eu
openssl_enc_opts=()
file_no_ext=$(basename "$@" .enc)
[[ $# != 1 ]] && { echo "Usage: $(basename $0) FILE_NAME.enc"; exit 1; }
[[ $file_no_ext == $1 ]] && { echo "The filename must end with '.enc'"; exit 1; }
[[ -v DECAT_PASS ]] && openssl_enc_opts+=(-pass env:DECAT_PASS)
openssl enc -aes-256-cbc -pbkdf2 -in "$@" -d "${openssl_enc_opts[@]}"
#!/bin/bash
# Inspired by https://www.meixler-tech.com/web-browser-based-file-encryption-decryption.html
set -eu
out_file="$(dirname "$@")/$(basename "$@" .enc)"
[[ $# != 1 ]] && { echo "Usage: $(basename $0) FILE_NAME.enc"; exit 1; }
[[ $out_file == $1 ]] && { echo "The filename must end with '.enc'"; exit 1; }
openssl enc -aes-256-cbc -pbkdf2 -in "$@" -out "$out_file" -d
#!/bin/bash
# Inspired by https://www.meixler-tech.com/web-browser-based-file-encryption-decryption.html
set -eu
[[ $# != 1 ]] && { echo "Usage: $(basename $0) FILE_NAME"; exit 1; }
openssl enc -aes-256-cbc -pbkdf2 -in "$@" -out "$@".enc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment