Skip to content

PGP Encrypt File

ts
// Encrypt a file for a recipient using their public key
var err = PGPEncryptFile(
  "/documents/confidential.pdf",      // Input file
  "/transfer/confidential.pdf.pgp",   // Output encrypted file
  "/keys/bob.pubkey"                  // Recipient's public key
);

Encrypts a file using the recipient's PGP public key. The output is an armored, encrypted file suitable for secure transfer.

Parameters

NameTypeDescription
inputFilestringPath to the file to encrypt
outputFilestringPath for the resulting encrypted file
recipientPubKeystringPath to the recipient's public key file

Returns

  • Returns null on success, or an error object if encryption fails.

NOTE

Only the recipient's public key is required for encryption. The sender's private key is not needed for basic encryption.

Example

ts
var err = PGPEncryptFile(
  "/data/budget.xlsx",
  "/data/budget.xlsx.pgp",
  "/keys/bob.pubkey"
);
if (err == null) {
  Log("File encrypted successfully!");
} else {
  Log("Encryption failed: " + err);
}