Created
October 4, 2022 14:16
-
-
Save chrisswanda/8b5c5ac942ae8fff1e937bfceffc99a2 to your computer and use it in GitHub Desktop.
Adding age functions in my bash_profile
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
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