Created
September 23, 2014 13:52
-
-
Save MartinNowak/882f394eb33ae3a183ff to your computer and use it in GitHub Desktop.
envelope encryption
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/sh | |
set -e | |
if [ $# -ne 1 ]; then | |
echo "usage: $0 <private_key>" | |
exit 1 | |
fi | |
KEYSIZE=256 | |
KEY=$(umask 0177 && KEY=$(mktemp) && head -c $((2 * KEYSIZE)) | openssl rsautl -decrypt -inkey ${1} > ${KEY} && echo ${KEY}) | |
function cleanup { rm -f ${KEY}; } | |
trap cleanup EXIT | |
openssl aes-256-cbc -d -salt -pass file:${KEY} |
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/sh | |
set -e | |
if [ $# -ne 1 ]; then | |
echo "usage: $0 <public_key>" | |
exit 1 | |
fi | |
KEYSIZE=256 | |
KEY=$(umask 0177 && KEY=$(mktemp) && openssl rand ${KEYSIZE} > ${KEY} && echo ${KEY}) | |
function cleanup { rm -f ${KEY}; } | |
trap cleanup EXIT | |
openssl rsautl -encrypt -inkey ${1} -pubin -in ${KEY} | |
openssl aes-256-cbc -salt -pass file:${KEY} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment