Skip to content

Instantly share code, notes, and snippets.

@DosAmp
Last active December 19, 2015 11:39
Show Gist options
  • Save DosAmp/5949399 to your computer and use it in GitHub Desktop.
Save DosAmp/5949399 to your computer and use it in GitHub Desktop.
Small drag-and-drop wrapper script for GnuPG
$gpgid = "DEADBEEF" # recipient ID (hex/email)
# add full path to binaries if needed
$gpgcommand = "gpg2"
$7zcommand = "7z"
foreach ($file in $args) {
$source = Get-Item -ErrorAction:SilentlyContinue $file
if ($source) {
if (-not $source.PSIsContainer) {
# file encryption/decryption
if ($source.Name.ToLower().EndsWith(".gpg")) {
# file decryption
$target = $source.FullName.Substring(0, $source.FullName.Length - 4)
& $gpgcommand "--decrypt" "--yes" "--output" $target $source
} else {
# file encryption
$target = $source.FullName + ".gpg"
& $gpgcommand "--encrypt" "--sign" "--recipient" $gpgid "--output" $target $source
}
} else {
# compress directory to temporary zip file
$tmpzipfile = [IO.Path]::GetTempPath() + [IO.Path]::GetRandomFileName()
& $7zcommand "a" "-tzip" "-mx=9" $tmpzipfile $source
# encrypt zip file
$target = $source.FullName + ".zip.gpg"
& $gpgcommand "--encrypt" "--sign" "--recipient" $gpgid "--compress-level" "0" `
"--output" $target $tmpzipfile
Remove-Item -Force $tmpzipfile
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment