Skip to content

Instantly share code, notes, and snippets.

@chrisswanda
Created October 4, 2022 14:16
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 chrisswanda/8b5c5ac942ae8fff1e937bfceffc99a2 to your computer and use it in GitHub Desktop.
Save chrisswanda/8b5c5ac942ae8fff1e937bfceffc99a2 to your computer and use it in GitHub Desktop.
Adding age functions in my bash_profile
I banged rocks together and came up with this. I was needing a quick way to do age encryption/decryption for various files.
Dropped this in my ~/.bash_profile.
age_encrypt()
{
pub_key=$(cat ~/.config/age/pubkey.pub.age)
if [ -f $1 ] ; then
case $1 in
*.age) echo "'$1' is not a valid file" && return 1 ;;
*) age -o $1.age -r $pub_key $1 ;;
esac
fi
}
age_decrypt()
{
priv_key=(~/.config/age/privkey.priv.age)
if [ -f $1 ] ; then
case $1 in
*.age) output=$(echo $1 | sed "s/\.age//") ;;
*) echo "'$1' is not a valid file" && return 1 ;;
esac
fi
age -d -i $priv_key $1 > $output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment