Skip to content

Instantly share code, notes, and snippets.

@MartinNowak
Created September 23, 2014 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinNowak/882f394eb33ae3a183ff to your computer and use it in GitHub Desktop.
Save MartinNowak/882f394eb33ae3a183ff to your computer and use it in GitHub Desktop.
envelope encryption
#!/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}
#!/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