Skip to content

Instantly share code, notes, and snippets.

Created July 9, 2013 05:14
Show Gist options
  • Save anonymous/5954886 to your computer and use it in GitHub Desktop.
Save anonymous/5954886 to your computer and use it in GitHub Desktop.
Hybrid symmetric encription/decryption of given file with generated key. Then encryption of generated key with given public key. Initial files are deleted.
#!/bin/bash
FILE=${1%.enc}
KEYNAME=$2
openssl rsautl -decrypt -inkey ${KEYNAME} < ${FILE}.key.enc > ${FILE}.key
openssl enc -aes-256-cbc -d -pass file:${FILE}.key < ${FILE}.enc > ${FILE}
rm ${FILE}.key.enc ${FILE}.enc
#!/bin/bash
function mkpw() {
head /dev/urandom | uuencode -m - | sed -n 2p | cut -c1-${1:-64};
}
FILE=$1
KEYNAME=$2
echo `mkpw` > ${FILE}.key
openssl enc -aes-256-cbc -pass file:${FILE}.key < ${FILE} > ${FILE}.enc
openssl rsautl -encrypt -pubin -inkey ${KEYNAME} < ${FILE}.key > ${FILE}.key.enc
rm ${FILE} ${FILE}.key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment