2

I am looking for help to figure out how to tie a secret key with a passphrase to encrypt a file using GPG. I had tested many option (--encrypt, --sign, --recipient, --symmetric, etc), but in all of them, I was able to decrypt the file typing only the passphrase, even in a machine where I don't have the public nor the private/secret keys.

Is there a way to force the user to have the secret key and to be asked to type the passphrase?

I am open to any other idea that force a double security check to decrypt the protected file.

I am using the GnuPG version 2.0.9 over Linux.

My test command lines included:

I have tried to protect my file using these different syntaxes: ###

gpg --encrypt --symmetric --sign file.txt

gpg --symmetric --sign file.txt

gpg --symmetric --recipient file.txt 

gpg -sb file.txt 

gpg --default-key AFAEF918 --encrypt file.txt 

In all attempts, the protected file was decrypted typing only the passphrase, even in one computer without the public/private keys.

/root/.gnupg/secring.gpg
sec 1024D/AFAEF918 2016-02-12
uid TEST User (TEST Dev GPG Key)
ssb 2048g/50B959DD 2016-02-12

Thanks,

2
  • I'm not really sure about what you executed exactly. Please provide the command line of the encryption statement, and the output of gpg -K on the machine where you wanted to decrypt the file (not having the private keys). – Jens Erat Feb 17 '16 at 23:02
  • I have tried to protect my file using these different syntaxes: ### gpg --encrypt --symmetric --sign file.txt AND gpg --symmetric --sign file.txt AND gpg --symmetric --recipient file.txt AND gpg -sb file.txt AND gpg --default-key AFAEF918 --encrypt file.txt ### In all attempts, the protected file was decrypted typing only the passphrase, even in one computer without the public/private keys. ##### /root/.gnupg/secring.gpg >>> sec 1024D/AFAEF918 2016-02-12 // uid TEST User (TEST Dev GPG Key) <myemail@gmail.com> // ssb 2048g/50B959DD 2016-02-12 – Emerson Ivo Feb 18 '16 at 1:43
7

Start by reading the GPG MiniHOWTO, and following the examples in there.

Then refer to the GPG manual for more information as required.

If possible

When experimenting, please use -v and -vv in order to see more information on what's happening.

--symmetric is specifically symmetric encryption, which is not supposed to use keys - it uses the passphrase only, so being able to decrypt with only the passphrase is expected.


Symmetric encryption - only a passphrase

The simplest --symmetric command line to encrypt is

gpg -v --symmetric test.txt

though I would strongly recommend choosing a better cipher and larger number of key derivation iterations, i.e.

gpg -v --cipher-algo AES256 --s2k-mode 3 --s2k-digest-algo SHA512 --s2k-count 65600000 --symmetric test.txt

for AES256 encryption with a SHA-512 digest and a large key iteration count (please increase it from what I've listed as well), or

gpg -v --cipher-algo CAMELLIA256 --s2k-mode 3 --s2k-digest-algo SHA512 --s2k-count 65600000 --symmetric test.txt

for CAMELLIA256 as above otherwise.


Signatures - no encryption by itself

-sb is two forms of signature together, and acts the same as -b. This DOES NOT ENCRYPT in the first place, it just signs with a detached signature; a more complete usage would be:

gpg -u <mykeyid> -b test.txt

for the detached signature


Public Key Encryption

A public key example of a signature plus encryption is:

gpg -v --local-user <mykeyidToSign> --recipient <theirkeyidToEncryptTo>  --sign --encrypt test.txt

Public key generation

I recommend a stronger passphrase encryption and digest algorithm when generating keys as well

gpg --s2k-mode 3 --s2k-digest-algo SHA512 --s2k-count 95600000 --cert-digest-algo SHA512 --gen-key

gpg --edit-key <mynewkey>

And, as above, increase --s2k-count further, please.

This not only creates a strong passphrase derivation, but also sets a strong, modern key self-signature (--cert-digest-algo). Some old or limited GPG or PGP software may not support new self-signatures of SHA512; you can use SHA256 instead there if you have to, but I rarely see issues with SHA512 these days (and they should upgrade if they have them).

Follow that up by setting preferences to the strongest defaults that you can, for example

gpg --edit-key <mynewkey>
setpref AES256 CAMELLIA256 AES192 CAMELLIA192 AES CAMELLIA128 3DES SHA512 SHA384 SHA256 SHA224 SHA1 BZIP2 ZIP ZLIB
save

this step is safe, as any properly configuring sending software will simply go down the list to find the first cipher that matches, the first hash that matches, and the first compression that matches.


Public key passphrases

Note that the passphrase (entered when generating the key, changable with the

passwd

command in the --edit-key mode, is what encrypts the private key; it is NOT used by whoever is using the public key, and SHOULD be kept as secret as the private key itself.


Both passphrase and public key encryption, requiring both

If you want the recipient to have BOTH the private key, AND a passphrase known by both parties (sender and recipient), then you have to run GPG twice, i.e.

gpg -v --cipher-algo CAMELLIA256 --s2k-mode 3 --s2k-digest-algo SHA512 --s2k-count 65600000 --symmetric test.txt

First use symmetric encryption, which will be the SECOND decryption (the "inside" layer of the encryption onion).

gpg -v --local-user <mykeyidToSign> --recipient <theirkeyidToEncryptTo>  --sign --encrypt test.txt.gpg

Then use public key encryption on the previously encrypted file; note this one is on test.txt.gpg, and outputs test.txt.gpg.gpg

The recipient (or their automated process) will first decrypt the public key portion with their private key as well as validate the signature. Then, if it's a corporatewide or team key, they can route the message to the intended recipient who has the symmetric key.


Decryption (both public and private)

gpg -v --decrypt test.txt.gpg
2
  • Thank you so much for your help. All yours statements above worked very well and were very very helpful. – Emerson Ivo Feb 18 '16 at 15:50
  • Somehow the "only passphrase" commands do not work. gpg always asks me for some recipient. If I add some email address as --recipient value, it will complain, that there is no public key for the email address. Apparently it still wants to use a public key of the recipient instead of only passphrase to encrypt. -- EDIT: It seems that was caused by me having the innocuous --encrypt as well. – Zelphir Kaltstahl Oct 10 '18 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.