0

How can I encrypt three different files, each with its own public key?

For instance, there are three companies (X, Y and Z). Each company sends me its own public key.

I want to send a file to each company and encrypt it using the correct matching key.

1- encrypt file1.txt by x.pub and send it to company X

2- encrypt file2.txt by y.pub and send it to company Y

3- encrypt file3.txt by z.pub and send it to company Z

How can I do the above in a Windows batch file?

Coops
  • 6,055
  • 1
  • 34
  • 54
Mohammad AL-Rawabdeh
  • 1,612
  • 12
  • 33
  • 54

1 Answers1

6

The problem is that you first have to import the keys in your keyring. After that it's quite easy to automate.

I believe that this should work:

gpg --no-default-keyring --keyring x.gpg --import x.pub
gpg --no-default-keyring --keyring x.gpg --encrypt file1.txt

gpg --no-default-keyring --keyring y.gpg --import y.pub
gpg --no-default-keyring --keyring y.gpg --encrypt file2.txt

gpg --no-default-keyring --keyring z.gpg --import z.pub
gpg --no-default-keyring --keyring z.gpg --encrypt file3.txt

Do note that the import step is only required the first time (assuming that you don't delete the x.gpg files.

Wolph
  • 865
  • 1
  • 7
  • 12
  • Looks right to me, three files, three keys. Not a script as such, but does the job! – Coops Mar 12 '11 at 16:50
  • when i execute the following command the following error appear :- `C:\>"C:\Program Files\GNU\GnuPG\gpg.exe" -r --no-default-keyring --keyring bank_1.gpg --encrypt D:\SSC\keys\port.txt gpg: --no-default-keyring: skipped: public key not found gpg: D:\SSC\keys\port.txt: encryption failed: public key not found` – Mohammad AL-Rawabdeh Mar 13 '11 at 11:04
  • @Mohammad AL-Rawabdeh: apparently `gpg` is having problems locating your public key in the keyring. Are you sure the path is correct? Did the `--import` step run without errors? – Wolph Mar 13 '11 at 19:12
  • yes `--import` run without any error – Mohammad AL-Rawabdeh Mar 14 '11 at 08:29