# PGP

CrushClient can encrypt or decrypt files with PGP while it transfers them, with any protocol. The file is never stored unencrypted on the way.

In the window, HTTPS connections to CrushMFT have **Encrypt files with a password (PGP)** in their advanced options. With keys, use the command line as below.

## Encrypt while uploading

Encrypt with the receiver's public key before the file leaves this computer. When the destination is a CrushMFT server, turn its MD5 check off, because the encrypted file no longer matches the original:

```
set md5_check false
config pgpEncryptUpload true
config pgpPublicKeyUploadPath /mypgpkeys/customer1_key.pub
connect https://user:pass@someserver.domain.com/
lcd /var/documents/
cd /
put test_file.txt
wait
quit
```

The `config` lines come before `connect`: they are options of that connection.

## Encrypt or decrypt a local file

Both sides can be this computer, which turns CrushClient into a PGP tool.

Encrypt with a public key:

```
java -jar CrushTunnel.jar inline_script "config pgpEncryptUpload true;config pgpPublicKeyUploadPath mykey.pub;connect file://;put plain.txt encrypted.txt;quit;"
```

Decrypt with a private key and its password:

```
java -jar CrushTunnel.jar inline_script "config pgpDecryptUpload true;config pgpPrivateKeyUploadPath mykey.key;config pgpPrivateKeyUploadPassword password;connect file://;put encrypted.txt plain.txt;quit;"
```

## The options

| Option | Meaning |
|---|---|
| `pgpEncryptUpload true` | encrypt what is uploaded |
| `pgpPublicKeyUploadPath <file>` | the public key to encrypt with |
| `pgpDecryptUpload true` | decrypt what is uploaded |
| `pgpPrivateKeyUploadPath <file>` | the private key to decrypt with |
| `pgpPrivateKeyUploadPassword <password>` | the private key's password |

## In your own Java code

The same classes are in `CrushTunnel.jar`:

```
// encrypt
GenericClient c = Common.getClient("file://", "", null);
c.setConfig("pgpEncryptUpload", "true");
c.setConfig("pgpPublicKeyPath", "/path/to/mykey.pub");
OutputStream out = c.upload("/path/to/destfile.txt", 0, true, true);
// write the bytes, then close out
c.logout();

// decrypt
GenericClient c = Common.getClient("file://", "", null);
c.setConfig("pgpDecryptUpload", "true");
c.setConfig("pgpPrivateKeyUploadPath", "/path/to/mykey.key");
c.setConfig("pgpPrivateKeyUploadPassword", "password");
OutputStream out = c.upload("/path/to/destfile.txt", 0, true, true);
// write the bytes of the encrypted file, then close out
c.logout();
```
