Another “at work” post!
I’ve been generating files which need to be distributed via a file server, but need to be encrypted using GPG (the open source PGP application). Rather than managing keys for a large number of users, instead, I have a text file with the user names in, and a batch file. Please see the below gist for details :)
Place this batch file and the text file into the same directory, edit the batch file to specify the key server and the text file to specify the names to encrypt.
If you hit an issue where an individual has multiple keys against their name, the script may well complain and ditch responses.
In this case, uncomment the line in the batch file which says: REM %COMMAND% --recv-keys <KEY ID>
So it should say instead: %COMMAND% --recv-keys DECAFBAD
recipient name@example.com | |
recipient name2@example.com |
@echo off | |
REM SCRIPTNAME: run_gpg.bat | |
REM AUTHOR: Jon Spriggs | |
REM VERSION: 1.0 | |
REM RELEASE: 2016-04-04 | |
REM LICENSE: GNU General Public License 3.0 | |
REM ABOUT: This script is used to automate the GPG encryption of any file to a series of email addresses. | |
REM NOTES: You must run this from the path where the batch file and text files are located. | |
set COMMAND=gpg --no-options | |
set COMMAND=%COMMAND% --trust-model always | |
set COMMAND=%COMMAND% --mangle-dos-filenames | |
set COMMAND=%COMMAND% --no-default-keyring | |
set COMMAND=%COMMAND% --keyserver ldap://your.key.server.here | |
set COMMAND=%COMMAND% --auto-key-locate keyserver | |
set COMMAND=%COMMAND% --quiet | |
set COMMAND=%COMMAND% --primary-keyring ".\pubring.pkr" | |
set COMMAND=%COMMAND% --secret-keyring ".\secring.skr" | |
REM If you need to add particular keys (for example, where several matching strings occur) then uncomment this line: | |
REM %COMMAND% --recv-keys <KEY ID> | |
set COMMAND=%COMMAND% --options ".\email address list.txt" | |
%COMMAND% --encrypt %1 | |
del pubring.* secring.* |