Created
July 9, 2013 05:14
-
-
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.
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 | |
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 |
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 | |
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