PGP signing (file, string, bytes)
function PGPSignFile(inFile: string, outFile: string, key: PGPKey | string, options?: object): boolean;
function PGPSignString(text: string, key: PGPKey | string, options?: object): PGPDataResult;
function PGPSignBytes(data: Uint8Array | number[] | string, key: PGPKey | string, options?: object): PGPDataResult;
// Original form
function PGPSignFile(inFile: string, sigFile: string, pubKeyFile: string, privKeyFile: string): boolean;NOTE
The original form of PGPSignFile is available as of Syncplify Server! v7.1.1. Everything else on this page is available as of Syncplify Server! v8.12.0.
A signature lets the recipient check, with your public key, that the data comes from you and was not changed. Signing does not encrypt: to do both in one step, use the SignWith option of the encryption functions.
key is your private key: a key object or the path of a private key file. A key that is protected by a passphrase must be loaded with it.
Signature modes
Mode | What is written | Equivalent |
|---|---|---|
"detached" (default) | Only the signature. You send it next to the data, which stays as it is. | gpg --detach-sign |
"clear" | The text itself followed by its signature, readable by people. For text only: strings and files. | gpg --clearsign |
"inline" | One OpenPGP message that contains both the data and the signature | gpg --sign |
PGPSignFile
Signs inFile and writes the signature, or the signed message, to outFile. Returns true on success; on failure PGPLastResult().ErrorMsg() says why.
var ours = PGPKey.FromSecret("pgp-private-key", "pgp-passphrase");
// Detached signature: send payroll.csv and payroll.csv.sig together
if (!PGPSignFile("/data/out/payroll.csv", "/data/out/payroll.csv.sig", ours)) {
Log.Error("signing failed: " + PGPLastResult().ErrorMsg());
}
// Cleartext signature of a text file
PGPSignFile("/data/out/manifest.txt", "/data/out/manifest.txt.asc", ours, { Mode: "clear" });Original form
PGPSignFile(inFile, sigFile, pubKeyFile, privKeyFile) still works and writes an armored detached signature. The signature is made with the private key, which must not be protected by a passphrase. The public key file must exist too.
PGPSignFile("/data/out/payroll.csv", "/data/out/payroll.csv.sig",
"/data/keys/partner-exchange.pubkey", "/data/keys/partner-exchange.privkey");PGPSignString
Signs a string. Data() of the result is ASCII armored text: the signature alone, or the signed message, depending on Mode.
var ours = PGPKey.FromSecret("pgp-private-key", "pgp-passphrase");
var manifest = "payroll.csv 18230 bytes\nbonus.csv 2210 bytes\n";
var res = PGPSignString(manifest, ours, { Mode: "clear" });
if (res.Ok()) {
WriteTextToFile("/data/out/manifest.asc", res.Data());
}PGPSignBytes
Signs binary data. data accepts the same kinds of value as the data of PGPEncryptBytes. Data() of the result is a byte array.
var ours = PGPKey.FromSecret("pgp-private-key", "pgp-passphrase");
var payload = new Uint8Array([0x50, 0x4b, 0x03, 0x04]);
var sig = PGPSignBytes(payload, ours); // detached, binary
if (!sig.Ok()) {
Log.Error("signing failed: " + sig.ErrorMsg());
}Options
| Option | Applies to | Explanation |
|---|---|---|
Mode | all | "detached" (default), "clear" or "inline". "clear" is not available for byte arrays. |
Armor | File, Bytes | true for ASCII armored output, false for binary. Default true for files and false for byte arrays. Strings and cleartext signatures are always armored. |
