Skip to content

Instantly share code, notes, and snippets.

@cypnk
Last active October 17, 2017 00:02
Show Gist options
  • Save cypnk/0310316eda0bce3a2276894bce011e99 to your computer and use it in GitHub Desktop.
Save cypnk/0310316eda0bce3a2276894bce011e99 to your computer and use it in GitHub Desktop.
Decrypt a file with a given private key (best for files encrypted with "encrypt.sh")
#!/bin/bash
# Decrypt a file using the specified private key
# Encrypted file
ENCF=$1
# Private key
PRVK=$2
# Decrypted file (defaults to the decrypted file name + ".decrypted")
DECF=${3:-$ENCF.decrypted}
if [ -f "$DECF" ]; then
echo "File with the decrypted filename already exists"
exit
fi
openssl rsautl -decrypt -inkey $PRVK -in $ENCF -out $DECF
exit
# To use this:
# sh decrypt.sh /path/to/file.ext.encrypted /path/to/privatekey.pem
# # To give specific name to the decrypted file:
# sh decrypt.sh /path/to/file.ext.encrypted /path/to/privatekey.pem /path/to/decrypted.file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment