Last active
October 17, 2017 00:02
-
-
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")
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 | |
# 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