Skip to content

PGP results and PGPLastResult ​

NOTE

Result objects and PGPLastResult are available as of Syncplify Server! v8.12.0.

The string and byte array functions return a result object. The file functions return only true or false, and PGPLastResult() hands you the result object behind that answer.

Every result has these two methods:

MethodReturnsExplanation
Ok()booleantrue when the call succeeded. For a verification, true means the signature is valid.
ErrorMsg()stringWhy the call failed; "" on success

Data result ​

Returned by the encryption and signing functions.

MethodReturnsExplanation
Data()string, byte array or nullThe output: a string from the String functions, a byte array from the Bytes functions, null on failure and for the File functions

Message result ​

Returned by the decryption and verification functions.

MethodReturnsExplanation
Data()string, byte array or nullThe content. It is null on failure, so content that failed a check is never handed out, and null for the File functions, which write a file instead.
Encrypted()booleanThe message was encrypted
FileName()stringFile name that the sender stored in the message. A hint, never a path to trust.
Signed()booleanThe message carried a signature
SignatureValid()booleanThe signature verified against one of the keys you gave
SignerKeyID()stringKey ID that the signature names. It proves nothing unless SignatureValid() is true.
SignerFingerprint()stringFingerprint of the key that made the verified signature; "" otherwise
SignedAt()Date or nullWhen the verified signature was made; null otherwise

Inspect result ​

Returned by the inspection functions, and described on their page.

PGPLastResult ​

ts
function PGPLastResult(): PGPDataResult | PGPMessageResult | PGPInspectResult | null;

Returns the result object of the most recent PGP function call in the running script, or null before the first one.

Last callResult returned
PGPEncryptFile, PGPSignFile, GeneratePGPKeys, and the String and Bytes forms of encryption and signingData result
PGPDecryptFile, PGPVerifyFile, and the String and Bytes forms of decryption and verificationMessage result
PGPInspectFile, PGPInspectString, PGPInspectBytesInspect result

PGPKey and the methods of a key object do not change it.

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

if (PGPDecryptFile("/data/in/report.csv.pgp", "/data/in/report.csv", ours, { VerifyWith: partner })) {
  var last = PGPLastResult();
  Log.Info("signed by " + last.SignerFingerprint() + " on " + FormatDateTime("YYYY-MM-DD HH:mm", last.SignedAt()));
} else {
  Log.Error("rejected: " + PGPLastResult().ErrorMsg());
}

TIP

Read PGPLastResult() right after the call you care about: the next PGP function call replaces it.

Common error messages ​

ErrorMsg() says what went wrong in plain words, and names the keys involved. The most frequent ones:

The message saysWhat it means
none of the keys given matchesThe message is encrypted to another key. The sender used a different public key, or the file is not meant for you.
load it with its passphraseA private key was loaded without its passphrase. Load it with PGPKey.FromFile or PGPKey.FromSecret and give the passphrase.
the message is protected by a passphraseThe message was encrypted to a passphrase, not to a key. Pass the Passphrase option.
only its public partA public key was given where the private key is needed, to decrypt or to sign
integrity check failedThe data changed after it was encrypted. Ask the sender to send it again.
is not signed, but a signature byVerifyWith is set and the message carries no signature
which is not among the keys givenThe signature was made by a key you did not pass. The sender signs with another key, or somebody else signed.
the signature is not validThe data changed after it was signed, or another key signed it
has expired, expired onThe key is past its expiry date. Ask its owner for a current one.
wrong passphraseThe passphrase does not open the key or the message
text outside the signed blockA signed message was passed with other text around it: see PGPVerifyString