# PGP task

A PGP task encrypts or decrypts the files on the list with PGP keys, where the files are. It is the task for "decrypt what the partner sent" and "encrypt before it leaves".

PGP uses two keys. A **public** key encrypts and can be given to anybody. The matching **private** key decrypts and never leaves its owner. So:

| To | You need |
|---|---|
| encrypt a file for a partner | the **partner's public** key |
| decrypt a file a partner sent | **your private** key, and its password |
| sign a file, so that the partner can check it is from you | **your private** key |
| check a signature | the **partner's public** key |

Keys are made and kept in the [PGP app](Web-PGP.md) of the admin pages. A key kept there is chosen in a key field with **Browse**, kind **PGP**, and needs no password in the task.

## Fields

| Field | What it does | On a new task |
|---|---|---|
| **Method** | **Encrypt**, **Decrypt** or **Info** | |
| **Private Public Key file** | the key, as a file on the server: the public key to encrypt with, or the private key to decrypt with. **Browse**, **Test**. | |
| **Key password (if any)** | the password of the private key | |
| **Delete Original?** | after encrypting, the plain file is deleted; after decrypting, the encrypted one | on |
| **Route connection through DMZ when possible** | the connection is made from a DMZ server | |

### For encrypting

| Field | What it does | On a new task |
|---|---|---|
| **Encryption cypher** | TRIPLE_DES, CAST5, BLOWFISH, AES_128, AES_192, AES_256, TWOFISH, DES, SAFER, IDEA. Use **AES_256** unless the partner cannot. | |
| **ASCII Armor?** | the encrypted file is text that survives mail and copy-and-paste; unticked, it is binary and smaller | off |
| **Sign**, **Private key to use for Signing** | the file is also signed with your private key | off |
| **Add hinted decrypted size.** | notes the plain size in the file, so that a CrushMFT server can show it for the encrypted file | on |

### For decrypting

| Field | What it does | On a new task |
|---|---|---|
| **Decrypt file name** | the name of the decrypted file. `{name}` means: the name that is stored inside the encrypted file. | `{name}` |
| **Verify**, **Public key to use for Verification** | the signature is checked against the sender's public key. A file without a valid signature fails: "Verification failed while decrypting!" | off |

### Encrypting with a password

For a partner without keys: write `password:` as the **Private Public Key file** and the password as the **Key password**. The file is then encrypted with that password alone, and anybody who knows it can decrypt it, with any PGP program.

## What it does to the files

| Method | On disk | On the list |
|---|---|---|
| **Encrypt** | `report.csv` gets a neighbour `report.csv.pgp`. While it is written it is named `report.csv.encrypting.pgp`. | the `.pgp` file takes the plain file's place |
| **Decrypt** | the decrypted file is written beside the encrypted one, under its stored name or the one you gave | the decrypted file takes the encrypted file's place |
| **Info** | nothing | the item gets the facts of the key |

With **Delete Original?** the other file is removed; without it, both are there afterwards.

Give the task a filter when the list is mixed: `*.pgp` for decrypting, so that files that are not encrypted pass untouched.

## Info

With the method **Info**, the items are key files, and each gets what the key says about itself as variables:

`{pgp_user_id}`, `{pgp_creation_time}`, `{pgp_expiration_date}`, `{pgp_is_expired}`, `{pgp_is_valid_forever}`, `{pgp_valid_days}`, `{pgp_algorithm}`, `{pgp_key_size}`, `{pgp_key_id_long_hex}`.

A job that runs monthly over the folder of partner keys and mails those with `{pgp_valid_days}` under 30 tells you before a partner's key runs out.

## Things to know

- **Encrypting needs no secret.** A job that only encrypts holds a public key and no password. Keep it that way: do not give it your private key "to be safe".
- **The private key's password** is stored encrypted in the job. Who may see it is a matter of rights: see [Who may see, change and run a job](Jobs-Access.md).
- **While copying.** A [Copy](Task-Copy.md) can encrypt or decrypt as it copies, so that the plain file never lies on a disk. Use that where the plain file must not exist on this server at all.
- **For a whole folder, always.** A folder can be set to encrypt everything that is stored in it, without a job: see [VFS: encrypted folders](VFS-Encrypted.md).
- **A wrong key** shows as an error of the task that names the key. The usual cause is that the file was encrypted for another key than the one you hold: ask the partner which key id they used, and compare with `{pgp_key_id_long_hex}`.
- **CMS / S/MIME** is the other common way to encrypt files, with certificates: [CMS](Task-CMS.md).
