Skip to content

OpenPGP: overview ​

SyncJS encrypts, decrypts, signs and verifies OpenPGP data held in files, in strings or in byte arrays. It works with GnuPG and with the OpenPGP support of other file transfer products: keys exported by gpg (RSA or Curve25519, with subkeys, protected by a passphrase), ASCII armored or binary messages, and detached, cleartext or inline signatures.

IMPORTANT

Everything in this section is available as of Syncplify Server! v8.12.0. Earlier versions have only the original calls, which keep working unchanged: see Scripts written before v8.12.

Functions ​

TaskFilesStringsByte arrays
EncryptPGPEncryptFilePGPEncryptStringPGPEncryptBytes
DecryptPGPDecryptFilePGPDecryptStringPGPDecryptBytes
SignPGPSignFilePGPSignStringPGPSignBytes
VerifyPGPVerifyFilePGPVerifyStringPGPVerifyBytes
Inspect without decryptingPGPInspectFilePGPInspectStringPGPInspectBytes

Keys are loaded or created with PGPKey, or with the original GeneratePGPKeys. PGPLastResult() tells why the last call failed, or who signed what it just read. Complete scripts are on the recipes page.

A first example ​

ts
var partner = PGPKey.FromFile("/data/keys/partner.asc");               // their public key
var ours    = PGPKey.FromSecret("pgp-private-key", "pgp-passphrase");  // our private key

// Outbound: only the partner can read it, and they can check that it comes from us
if (!PGPEncryptFile("/data/out/payroll.csv", "/data/out/payroll.csv.pgp", partner, { SignWith: ours })) {
  Log.Error("encryption failed: " + PGPLastResult().ErrorMsg());
}

// Inbound: no output file unless the partner signed the message
if (!PGPDecryptFile("/data/in/report.csv.pgp", "/data/in/report.csv", ours, { VerifyWith: partner })) {
  Log.Error("rejected: " + PGPLastResult().ErrorMsg());
}

Rules shared by every function ​

Keys ​

Wherever a function takes a key, you can pass:

  • a key object returned by PGPKey,
  • the path of a key file, as a string, or
  • an array of either, where several keys make sense (recipients, decryption keys, verification keys).

A path is the short way. A key object lets you check the fingerprint and the expiry date first, supply a passphrase, and load the key once for many files.

Options ​

The last argument of most functions is an optional object, such as { SignWith: ours, Armor: false }.

  • Option names are not case sensitive.
  • An unknown option name throws, so a typing mistake cannot silently change what happens.
  • SignWith or VerifyWith set to null or undefined throws. That is usually a variable that was never assigned, and ignoring it would send unsigned data or skip the signature check. Leave the option out when you do not want it.

Failures ​

What goes wrongWhat happens
PGPKey cannot load or create a keyThe call throws. The script stops unless you catch the error.
A mistake in the call itself: an unknown option, an argument of the wrong kindThe call throws.
The operation fails: wrong key, bad signature, damaged data, missing fileFile functions return false. String and byte array functions return a result whose Ok() is false.

Every failure is also written to the log, with its reason.

Output files ​

An output file is written only when the whole operation succeeded. A decryption whose integrity check or signature check fails leaves no output file behind, and does not touch a file that already exists at that path. Writing the output onto the input file is safe.

File paths ​

The file functions work on the local file system of the machine that runs the script, with the paths of its operating system. On Windows, double the backslashes: "C:\\Keys\\partner.asc".

In Syncplify Server!, a file that a client uploaded lives in a VFS, which may be a cloud bucket or an encrypted folder. Export it to a local file first, as shown in Decrypt an upload in an event handler.

TIP

Use the file functions for anything large. They process the data as a stream, while the string and byte array functions hold all of it in memory.

Algorithms ​

Messages are encrypted with AES-256 whenever the recipient keys accept it, and signatures use SHA-256. There is nothing to configure.