Last active
January 30, 2025 03:32
-
-
Save giner/fd417991d6ba457900c5f63fa39d4fb7 to your computer and use it in GitHub Desktop.
Encrypt / Decrypt files with OpenSSL
This file contains 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 | |
# 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[@]}" |
This file contains 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 | |
# 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 |
This file contains 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 | |
# 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