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
| Method | Returns | Explanation |
|---|---|---|
Ok() | boolean | false when the data is not OpenPGP data, or cannot be read |
ErrorMsg() | string | Why Ok() is false; "" otherwise |
Kind() | string | "message", "signature", "publickey", "privatekey" or "cleartext" (a cleartext signed message); "" when Ok() is false |
Armored() | boolean | The data is ASCII armored |
Encrypted() | boolean | The data is an encrypted message |
PassphraseEncrypted() | boolean | The message can be opened with a passphrase |
RecipientKeyIDs() | array | Key IDs the message is encrypted to. 0000000000000000 is a recipient that the sender chose to hide. |
Signed() | boolean | A signature is visible |
SignerKeyIDs() | array | Key IDs that the visible signatures name |
LegacyArmor() | boolean | The 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()andSignerKeyIDs()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
KeyIDof 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());
}