GeneratePGPKeys (key pair files)
ts
function GeneratePGPKeys(keyPairName: string, directory: string, bits: number): boolean;The original key generator. It creates an RSA key and writes its two halves to directory:
<keyPairName>.pubkey: the ASCII armored public key, to give to your partners<keyPairName>.privkey: the ASCII armored private key, to keep to yourself
| Parameter | Type | Requirement | Explanation |
|---|---|---|---|
keyPairName | string | required | Base name of the two files. It also becomes the user ID of the key. |
directory | string | required | Existing directory in which the files are written |
bits | number | required | RSA key size, 2048 or more; 4096 is a good choice |
| Return value | Explanation |
|---|---|
true | Both files were written |
false | Generation failed; PGPLastResult().ErrorMsg() says why |
WARNING
The private key file is not protected by a passphrase: whoever can read the file can decrypt and sign with it. For a key with a passphrase, an email address, an expiry date or Curve25519, use PGPKey.Generate instead.
NOTE
As of v8.12 the keys this function writes can be imported by GnuPG and other OpenPGP software. Keys it wrote in earlier versions keep working in SyncJS: see Scripts written before v8.12.
Example
ts
if (GeneratePGPKeys("partner-exchange", "/data/keys", 4096)) {
Log.Info("send /data/keys/partner-exchange.pubkey to your partner");
} else {
Log.Error("key generation failed: " + PGPLastResult().ErrorMsg());
}