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:
| Method | Returns | Explanation |
|---|---|---|
Ok() | boolean | true when the call succeeded. For a verification, true means the signature is valid. |
ErrorMsg() | string | Why the call failed; "" on success |
Data result
Returned by the encryption and signing functions.
| Method | Returns | Explanation |
|---|---|---|
Data() | string, byte array or null | The 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.
| Method | Returns | Explanation |
|---|---|---|
Data() | string, byte array or null | The 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() | boolean | The message was encrypted |
FileName() | string | File name that the sender stored in the message. A hint, never a path to trust. |
Signed() | boolean | The message carried a signature |
SignatureValid() | boolean | The signature verified against one of the keys you gave |
SignerKeyID() | string | Key ID that the signature names. It proves nothing unless SignatureValid() is true. |
SignerFingerprint() | string | Fingerprint of the key that made the verified signature; "" otherwise |
SignedAt() | Date or null | When the verified signature was made; null otherwise |
Inspect result
Returned by the inspection functions, and described on their page.
PGPLastResult
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 call | Result returned |
|---|---|
PGPEncryptFile, PGPSignFile, GeneratePGPKeys, and the String and Bytes forms of encryption and signing | Data result |
PGPDecryptFile, PGPVerifyFile, and the String and Bytes forms of decryption and verification | Message result |
PGPInspectFile, PGPInspectString, PGPInspectBytes | Inspect result |
PGPKey and the methods of a key object do not change it.
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 says | What it means |
|---|---|
none of the keys given matches | The 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 passphrase | A 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 passphrase | The message was encrypted to a passphrase, not to a key. Pass the Passphrase option. |
only its public part | A public key was given where the private key is needed, to decrypt or to sign |
integrity check failed | The data changed after it was encrypted. Ask the sender to send it again. |
is not signed, but a signature by | VerifyWith is set and the message carries no signature |
which is not among the keys given | The signature was made by a key you did not pass. The sender signs with another key, or somebody else signed. |
the signature is not valid | The data changed after it was signed, or another key signed it |
has expired, expired on | The key is past its expiry date. Ask its owner for a current one. |
wrong passphrase | The passphrase does not open the key or the message |
text outside the signed block | A signed message was passed with other text around it: see PGPVerifyString |
