pgp
- Description:
The
pgpservice provides PGP encryption and decryption capabilities for both strings and files. String methods work with armored ASCII PGP keys and produce armored ASCII output. File methods read and write files in the virtual file system.Example of encrypting and decrypting a string:
var encrypted = pgp.encrypt("Hello, World!", armoredPublicKey); var decrypted = pgp.decrypt(encrypted, armoredPrivateKey, "my passphrase");PGP keys can be stored on folders via Config2_Folder#pgpPublicKey and Config2_Folder#pgpPrivateKey. The
encryptFileanddecryptFilemethods automatically use these folder keys, searching the input file's folder and walking up the hierarchy until a key is found. This means non-admin users in triggers and scripts can encrypt and decrypt files without needing direct access to the keys:pgp.encryptFile("/Outbound/report.csv", "/Outbound/report.csv.pgp"); pgp.decryptFile("/Inbound/data.csv.pgp", "/Inbound/data.csv");To supply keys explicitly, use
encryptFileWithKeyanddecryptFileWithKey:pgp.encryptFileWithKey("/data/report.csv", "/data/report.csv.pgp", armoredPublicKey); pgp.decryptFileWithKey("/data/report.csv.pgp", "/data/report.csv", armoredPrivateKey, "my passphrase");
Methods
| Method | Returns | Description |
|---|---|---|
| decrypt() | String | Decrypts an armored ASCII PGP ciphertext string using the given private key and passphrase, and returns the original plaintext string. |
| decryptFile() | void | Decrypts the contents of a PGP-encrypted file using the PGP private key from the folder hierarchy. |
| decryptFileWithKey() | void | Decrypts the contents of a PGP-encrypted file using an explicit private key and passphrase, and writes the decrypted output to another file. |
| encrypt() | String | Encrypts a plaintext string using the given PGP public key and returns the encrypted result as an armored ASCII string. |
| encryptFile() | void | Encrypts the contents of a file using the PGP public key from the folder hierarchy. |
| encryptFileWithKey() | void | Encrypts the contents of a file using an explicit PGP public key and writes the encrypted output to another file. |
| isEncrypted() | Boolean | Checks whether a file appears to be PGP-encrypted by inspecting its first bytes. |
Method Details
(static) decrypt(ciphertext, privateKey, passphrase) → {String}
- Description:
Decrypts an armored ASCII PGP ciphertext string using the given private key and passphrase, and returns the original plaintext string.
Parameters:
| Name | Type | Description |
|---|---|---|
ciphertext |
String | The armored ASCII PGP ciphertext to decrypt. |
privateKey |
String | The armored ASCII PGP private key. |
passphrase |
String | The passphrase to unlock the private key. |
Returns:
The decrypted plaintext string.
- Type
- String
(static) decryptFile(inputFile, outputFileopt)
- Description:
Decrypts the contents of a PGP-encrypted file using the PGP private key from the folder hierarchy. CompleteFTP searches the input file's folder and its ancestors for a Config2_Folder#pgpPrivateKey to use. This allows triggers and scripts to decrypt files without needing admin access to retrieve the key.
If
outputFileis omitted or is the same path asinputFile, the file is decrypted in place (via a temporary file).File arguments may be either a path string or a File object.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
inputFile |
String | File | The PGP-encrypted source file to decrypt. |
|
outputFile |
String | File |
<optional> |
The destination file for the decrypted output. If omitted, the file is decrypted in place. |
(static) decryptFileWithKey(inputFile, outputFile, privateKey, passphrase)
- Description:
Decrypts the contents of a PGP-encrypted file using an explicit private key and passphrase, and writes the decrypted output to another file. If
inputFileandoutputFileare the same path, the file is decrypted in place.File arguments may be either a path string or a File object.
Parameters:
| Name | Type | Description |
|---|---|---|
inputFile |
String | File | The PGP-encrypted source file to decrypt. |
outputFile |
String | File | The destination file for the decrypted output. May be the same as inputFile. |
privateKey |
String | The armored ASCII PGP private key. |
passphrase |
String | The passphrase to unlock the private key. |
(static) encrypt(plaintext, publicKey) → {String}
- Description:
Encrypts a plaintext string using the given PGP public key and returns the encrypted result as an armored ASCII string.
Parameters:
| Name | Type | Description |
|---|---|---|
plaintext |
String | The plaintext string to encrypt. |
publicKey |
String | The armored ASCII PGP public key. |
Returns:
The encrypted ciphertext as an armored ASCII string.
- Type
- String
(static) encryptFile(inputFile, outputFileopt)
- Description:
Encrypts the contents of a file using the PGP public key from the folder hierarchy. CompleteFTP searches the input file's folder and its ancestors for a Config2_Folder#pgpPublicKey to use. This allows triggers and scripts to encrypt files without needing admin access to retrieve the key.
If
outputFileis omitted or is the same path asinputFile, the file is encrypted in place (via a temporary file).File arguments may be either a path string or a File object.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
inputFile |
String | File | The source file to encrypt. |
|
outputFile |
String | File |
<optional> |
The destination file for the encrypted output. If omitted, the file is encrypted in place. |
(static) encryptFileWithKey(inputFile, outputFile, publicKey)
- Description:
Encrypts the contents of a file using an explicit PGP public key and writes the encrypted output to another file. If
inputFileandoutputFileare the same path, the file is encrypted in place.File arguments may be either a path string or a File object.
Parameters:
| Name | Type | Description |
|---|---|---|
inputFile |
String | File | The source file to encrypt. |
outputFile |
String | File | The destination file for the encrypted output. May be the same as inputFile. |
publicKey |
String | The armored ASCII PGP public key. |
(static) isEncrypted(file) → {Boolean}
- Description:
Checks whether a file appears to be PGP-encrypted by inspecting its first bytes. Detects both binary OpenPGP packets and ASCII-armored messages. This is useful in triggers to decide whether a file needs decryption without relying on file extensions.
if (pgp.isEncrypted(event.virtualPath)) { pgp.decryptFile(event.virtualPath, outputPath); }The file argument may be either a path string or a File object.
Parameters:
| Name | Type | Description |
|---|---|---|
file |
String | File | The file to check. |
Returns:
True if the file appears to be PGP-encrypted.
- Type
- Boolean