Skip to content

Instantly share code, notes, and snippets.

@cypnk
Created October 16, 2017 23:55
Show Gist options
  • Save cypnk/03ee811b7c6ce17f8ee9c9d9eed1d434 to your computer and use it in GitHub Desktop.
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)
#!/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