I have about twenty files symmetrically encrypted with CAST5. I have a single passphrase that is meant to work with all of the files and I wish to confirm that it does. I wrote a script to perform a check a check on each file.read passfor file in *.gpg ; do   if ! gpg --batch --passphrase $pass -d $file &>/dev/null ; then      echo Passphrase invalid for '$file'.   fidoneMy method of checking to see if the passphrase is valid for each file requires the decryption of the entire file, which is extremely slow. Is there a quicker way to do what I am attempting to do?
Checking if a passphrase is able to decrypt symmetrically encrypted files
shell script;encryption;gpg
Unfortunately there is no way of asking gpg-agent whether a key is passphrase protected. But you need not check the files but each key once only. Thus you should first check which keys are involved. There is no need to check the same key twice (by using it to decrypt two files).I have to admit that though I consider myself a GnuPG expert I don't get this done in an elegant way thus I have just asked on the GnuPG mailing list. I will edit this answer when I have the info from there.Edit 1Took the masters a few minutes only... The solution is: --list-onlygpg --status-fd 1 --list-only --list-packets file.gpg |   awk '$2 == ENC_TO {print 0x $3; }'gives you the key ID(s). Before you try to decrypt a file you check whether one of its recipient keys is in the list of keys which you have already checked.The slow operation is the asymmetric decryption. Nonetheless you should sort the files by size and start with the smallest.The above command gives you the subkey (if it was encrypted for a subkey). If you want to be really good then you don't compare the subkeys but the respective main keys. In every normal installation the main key and the subkeys have the same passphrase (with GnuPG you even have to fight to give them different passphrases).