Generate a PGP Key Pair
ts
function GeneratePGPKeys(keyPairName: string, directory: string, bits: number): boolean;Generates a new RSA PGP key pair and saves the armored public and private keys as separate files in directory. The key files are named after keyPairName with .pubkey and .privkey extensions.
Parameters
| Name | Type | Description |
|---|---|---|
| keyPairName | string | Base name for the key files (no extension) |
| directory | string | Directory where the key files will be saved |
| bits | number | RSA key size in bits (recommended: 2048 or 4096) |
- The public key will be saved as
<directory>/<keyPairName>.pubkey - The private key will be saved as
<directory>/<keyPairName>.privkey
Returns
| Return value | Explanation |
|---|---|
true | Key pair generated successfully |
false | Generation failed (invalid path, insufficient permissions, etc.) |
NOTE
Always protect your private key files. Use secure file permissions and consider storing the key path in the secret store rather than hardcoding it in your script.
Example
ts
// Generate a 4096-bit RSA key pair for alice
var ok = GeneratePGPKeys("alice", "/keys", 4096);
if (ok) {
Log("Key pair generated: /keys/alice.pubkey and /keys/alice.privkey");
} else {
Log("Key generation failed.");
}