Skip to content

PGP inspection (file, string, bytes) ​

ts
function PGPInspectFile(path: string): PGPInspectResult;
function PGPInspectString(text: string): PGPInspectResult;
function PGPInspectBytes(data: Uint8Array | number[] | string): PGPInspectResult;

NOTE

These functions are available as of Syncplify Server! v8.12.0.

Reports what a piece of OpenPGP data is, without decrypting anything and without needing a key. Use it to tell encrypted files from plain ones, to choose how to handle an incoming file, or to confirm before an upload that a file really is encrypted.

The result ​

MethodReturnsExplanation
Ok()booleanfalse when the data is not OpenPGP data, or cannot be read
ErrorMsg()stringWhy Ok() is false; "" otherwise
Kind()string"message", "signature", "publickey", "privatekey" or "cleartext" (a cleartext signed message); "" when Ok() is false
Armored()booleanThe data is ASCII armored
Encrypted()booleanThe data is an encrypted message
PassphraseEncrypted()booleanThe message can be opened with a passphrase
RecipientKeyIDs()arrayKey IDs the message is encrypted to. 0000000000000000 is a recipient that the sender chose to hide.
Signed()booleanA signature is visible
SignerKeyIDs()arrayKey IDs that the visible signatures name
LegacyArmor()booleanThe data carries the armor header that versions before v8.12 wrote: see Scripts written before v8.12

IMPORTANT

  • The signature of an encrypted message is inside the encryption. Signed() and SignerKeyIDs() are therefore known only for data that is not encrypted.
  • A recipient key ID usually names the encryption subkey of a key, which is not the KeyID of its key object. To find out whether one of your keys opens a message, pass your keys to a decryption function: the right one is picked.
  • Nothing here is verified. A key ID in a signature proves nothing until a verification succeeds.

Examples ​

ts
// Refuse to upload anything that is not encrypted
var info = PGPInspectFile("/data/out/payroll.csv.pgp");
if (!info.Ok() || !info.Encrypted()) {
  Log.Error("refusing to upload: the file is not an encrypted OpenPGP message");
  Exit(1);
}
ts
// Decide what to do with an incoming file
var info = PGPInspectFile("/data/in/incoming.dat");
if (!info.Ok()) {
  Log.Info("plain file, nothing to decrypt");
} else if (info.Kind() === "message" && info.Encrypted()) {
  Log.Info("encrypted message, armored: " + info.Armored());
} else if (info.Kind() === "cleartext" || info.Signed()) {
  Log.Info("signed, not encrypted");
} else {
  Log.Info("OpenPGP data of kind " + info.Kind());
}