7 ms·
For GPG symmetric encryption, the kind the article describes, here are the best options I've found for my typical case: gpg --symmetric \ --cipher-algo a
by jph 10y ago
For GPG symmetric encryption, the kind the article describes, here are the best options I've found for my typical case:
gpg --symmetric \
--cipher-algo aes256 \
--digest-algo sha256 \
--cert-digest-algo sha256 \
--compress-algo none -z 0 \
--quiet --no-greeting \
--no-use-agent "$@"
I keep this command here:
https://github.com/SixArm/gpg-encrypt
The options are chosen to balance tradeoffs of convenience, strength, and portability.
- api 10y agoThis illustrates what's wrong with GPG: it's too hard to use. Why so many arguments for a common task? Why aren't the defaults acceptable?
- RMarcus 10y agoThe defaults are acceptable, and will produce a symmetrically encrypted file that can be quickly decrypted on even low-powered ARM cores in a reasonable amount of time. These suggestions strike a different balance between protection and speed.
- tptacek 10y agoYou can safely just use "gpg -c" to encrypt files.
- brotherjerky 10y agoDoes `-no-use-agent` work? I see this in man: --no-use-agent This is dummy option. gpg always requires the agent.
- jwilk 10y agoContemporary versions of GnuPG (>= 2.1 IIRC) always use gpg-agent, and this option does nothing except producing a warning: gpg: WARNING: "--no-use-agent" is an obsolete option - it has no effect
- jph 10y agoI'll remove it now. It was useful to have (for me) for GPG version 1 when I connected to machines via SSH and didn't want a GPG agent pop up UI, and didn't have an easy way to change the GPG agent settings.
- digler999 10y agodo you know if gpg embeds a header in the cyphertext ? It always bothered me that openssl (for symmetric aes) puts "Salted_" as the first 7 bytes in every encrypted file, because it seems to nullify the "plausible deniability" defense and the "cyphertext should be indistinguishable from random data" tenet. Sure, having "Salted" doesn't prove that AES was run on the following bytes, but there's no plausible explanation as to what other program would do such a thing.
- viraptor 10y ago> do you know if gpg embeds a header in the cyphertext ? $ file /tmp/something.gpg /tmp/something.gpg: GPG symmetrically encrypted data (AES cipher) It has to, otherwise you'd have to know and use exactly the same options when decrypting. You could always strip it manually if you don't want this...
- twr 10y agoHere's an alternative to wrapping GPG, using .gnupg/gpg.conf: personal-cipher-preferences AES256 AES personal-digest-preferences SHA256 SHA512 personal-compress-preferences Uncompressed default-preference-list SHA256 SHA512 AES256 AES Uncompressed cert-digest-algo SHA256 s2k-cipher-algo AES256 s2k-digest-algo SHA256 s2k-mode 3 s2k-count 65011712 disable-cipher-algo 3DES weak-digest SHA1 force-mdc Note that these options impact compatibility with other GPG/PGP clients.
- jph 10y agoThanks, I've added your info to the README and a credit to you.
- larose 10y agoI did something similar to gpg-encrypt: https://github.com/larose/eef/ https://github.com/larose/eef/ It's a wrapper for gpg to edit encrypted files.
- davidcollantes 10y agoNice script, though I must note that it will only work on Linux. Tried it on macOS, but there is no `/dev/shm`.
- tptacek 10y agoWhat is this getting you that a simple 'gpg -c' isn't? (I'm asking seriously; I don't have a strong opinion about GPG command line arguments)
- mayailurus 10y agoOne thing that that gives you is the MDC packet, which isn't enabled by default in gpg classic. (Hence the parade of "message was not integrity protected" warnings.) It can be requested directly via '--force-mdc', but, as long as you're tweaking the configuration, you might as well boost everything up to the full "Grovergeddon" settings.
- throwawayish 10y agoThe defaults he has chosen hints at a distro that ships GPG v1 / classic, which has stranger defaults than GPG v2. IIRC the default ciphers are CAST5, (very slow) compression is on by default, hashes are RIPEMD I believe and so on
- acqq 10y agoExactly. The defaults of GPG 1, the one which can be used as a single not-too-big binary, seem to be poor. GPG 2 has better defaults, but it grew to include the kitchen sink and have a lot of moving parts, and I'd still prefer to have a good smaller program that does only a few things but do them good. My ideal would be a small executable with as little dependencies as possible.
- teddyh 10y agoLike gpgv or symcryptrun, maybe? https://gnupg.org/documentation/manuals/gnupg/gpgv.html#gpgv https://gnupg.org/documentation/manuals/gnupg/gpgv.html#gpgv https://gnupg.org/documentation/manuals/gnupg/symcryptrun.html#symcryptrun https://gnupg.org/documentation/manuals/gnupg/symcryptrun.ht...
- tptacek 10y agoThe GPG1 defaults are definitely not great, but I'm not sure they have much practical impact for this use case.
- vesinisa 10y agoYou can also explore the --s2k-* options to add a level of difficulty to hashing the password to protect against brute-forcing. E.g. --s2k-mode 3 --s2k-digest-algo sha512 --s2k-count 1000000 Default is to use salt + one round of SHA1, which is relatively weak.
- jph 10y agoThank you. I added your options to the repo and thanked you there too.
- txutxu 10y agoRegarding the code... set -euf onecmd --args "$@" The set -u is unneeded, as there are no code variables involved. The set -e is not needed, as there is only one command, and the script will return the exit status of such command. Always. And will exit after that command. Always. The set -f, will disable globbing, which I'm not sure it's what you want, when using a simple wrapper passing "$@" as filenames to gpg...
- jph 10y agoYou're correct. I use -euf as a default for new scripts, until someone asks for relaxing these. I'll remove the -f now because you're right, globbing can be useful.
- Wilya 10y agoNot the author of the code, but personally, I don't see any downside to putting "set -eu" at the beginning of every script I write. These should be defaults.
- nothrabannosir 10y agoI disagree. set -eu should be at the top of every bash script. This is the classic braceless if-guard mistake; leave it out today because you don't need it, forget, add something tomorrow and it breaks.
- switch007 10y agoYou can over-rely on "set -e" however: #!/usr/bin/env bash set -e fail() { false ; echo hello; } if ! fail; then :; fi That outputs "hello" and exits with 0.