Generate a PGP Key Pair
ts
// Generate a 2048-bit RSA key pair and save to files
var err = GeneratePGPKeys("/path/to/keys", "alice", 2048);
// Creates: /path/to/keys/alice.pubkey and /path/to/keys/alice.privkeyGenerates a new RSA PGP key pair and saves the armored public and private keys as files in the specified directory.
Parameters
| Name | Type | Description |
|---|---|---|
| dir | string | Directory where the key files will be saved |
| keyName | string | Base name for the key files (no extension) |
| bits | number | RSA key size (recommended: 2048 or 4096) |
- The public key will be saved as
<keyName>.pubkey - The private key will be saved as
<keyName>.privkey
Returns
- Returns
nullon success, or an error object if key generation fails.
NOTE
Always protect your private key files. Use secure file permissions and consider encrypting them with a passphrase.
Example
ts
var err = GeneratePGPKeys("/keys", "alice", 2048);
if (err == null) {
Log("Key pair generated successfully!");
} else {
Log("Key generation failed: " + err);
}