Skip to content

Instantly share code, notes, and snippets.

@yottatsa
Last active November 13, 2018 19:55
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 yottatsa/4e30d2059d72a5bd61c8b3792eebb9d8 to your computer and use it in GitHub Desktop.
Save yottatsa/4e30d2059d72a5bd61c8b3792eebb9d8 to your computer and use it in GitHub Desktop.
re-crypt asymmetrically encrypted files using symmetric encryption (e.g for back up)
#!/bin/sh -eu
# this is a self-verifying shell script
exec sh -eu -c "$(gpg -o - --verify "${0}")" "${0}" "$@"
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
#!/bin/sh -eu
set -o pipefail
exec 2>> "${0}.log"
set -x
if test "$#" -eq 0
then
DIR="$(mktemp -d)"
cp "${0}" "${DIR}/"
echo "${DIR}"
echo "${PASSPHRASE}"
exec find ./ -name '*.gpg' ! -path '*/vk/*' -print0 | exec xargs -0 "${0}" "${DIR}"
else
DIR="${1}"
shift
for f
do
out="${DIR}/$(dirname "${f}")"
mkdir -p "${out}"
file="$(basename "${f}")"
temp="$(mktemp "${out}/${file}.XXXXXX")"
gpg --decrypt -o - "${f}" | gpg -c --passphrase "${PASSPHRASE}" --batch --armor > "${temp}"
mv "${temp}" "${out}/${file}"
done
fi
-----BEGIN PGP SIGNATURE-----
iQIzBAEBCAAdFiEEUivlR1m9a/9HyLuX2rsuCYkqnPIFAlvrJdYACgkQ2rsuCYkq
nPKXlg/7BIdIgSNBdMVx5301YIDt5gX9NgT32h4ApeSeuFw4ab4B+JrNQBFhQpbk
3R17l62zHJyURBUN8LPzzWxStewPfX5xL07KoveZ56A8veFDxIfQHypFtvuwshRX
ctRhUxOW6mTpHcbrBhzPMdmJIo7FPfV40S/zZ/XPCFobz+0o7Dq0qdVkvm24xAmS
4yzmbJULaZe276ENI1ZErh5AEWDLrT0T+GlSozcAuwOLuYKS8vDvOda+xng/+HIy
wU+EfVQ0Os5w4k8G7ocrto43Y8ZLfs2+GJSSjrQemlxTNjXCpKRk5WW3+ZJtatsV
/vrnKbIqaIymRttv0O2xW5Q+SKhq10QLnoOxuHthDDmYD5XWJWj2/26mVoCJ6+xd
2yoD103btvwpdHoC809W6EfHL/0eXgkTqdTMjYWx0gwNdLAY0WlEV8cAq1o4rHnS
Tb3Km9A0JmFGGERxYU7dWY7dgtNoxipq5bnCCsBY6ekVOrbHYzxBQfTY9dtnkNUr
DMxmGL8gDY04CY7R9AMH103bctDdK5OtpedZUs255K12jiSa5YDPljwpC0+Wmd7d
sXuVCRsOdYMW+BHRu+dORhaOTDm+ScmvxSTsZV3/wtCtyejDJknqLKC3byuKqUqw
GuACQB6ps+G9sO7Auc0ELDJXtoNlyXK2slBdRNyd8CfRVbhNrWs=
=5ipb
-----END PGP SIGNATURE-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment