Created
October 16, 2017 23:55
-
-
Save cypnk/03ee811b7c6ce17f8ee9c9d9eed1d434 to your computer and use it in GitHub Desktop.
Encrypt a file with a given pubic key (to send to someone else)
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 | |
# Encrypt a file using the specified public key | |
# Source file | |
SRCF=$1 | |
# Public key | |
PUBK=$2 | |
# Encrypted file (defaults to the encrypted file name + ".encrypted") | |
ENCF=${3:-$SRCF.encrypted} | |
if [ -f "$ENCF" ]; then | |
echo "File with the encrypted filename already exists" | |
exit | |
fi | |
openssl rsautl -encrypt -inkey $PUBK -pubin -in $SRCF -out $ENCF | |
exit | |
# To use this: | |
# sh encrypt.sh /path/to/file.ext /path/to/publickey.pub | |
# To give specific name to the encrypted file: | |
# sh encrypt.sh /path/to/file.ext /path/to/publickey.pub /path/to/encrypted.file | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment