|
Generate the OpenPGP key
To generate the OpenPGP key (key pair), use the instance of TElPGPSecretKey class.
You can generate the key synchronously or in asynchronous mode.
Asynchronous mode lets you generate the key in background (secondary thread is spawned for generation).
To synchronously generate the key, call Generate() method of TElPGPSecretKey class.
You will need to provide the following parameters:
- Password to be used for encrypting the secret key
- KeyBits, which specifies the length of the key in bits.
The actual (generated) key length can be slightly larger.
The key length less than 1024 bits is not recommended due to low security of such keys.
- PublicKeyAlgorithm, which specifies the asymmetric algorithm, for which the keys are generated.
- SubkeyBits and SubkeyAlgorithm.
These properties correspond to KeyBits and PublicKeyAlgorithm described above.
They are used for subkey.
The subkey is a keypair, linked to the main key pair.
If the main key pair uses DSS public key algorithm, this key pair can be used only for signing and verification of the data, but not for encryption/decryption.
In such case the subkey is created and used for encryption and decryption operations.
- Username for the key to be assigned to.
- UseOldFormat flag, which defines format of key writing.
Old format is needed for the key to be read by PGP 2.6.x and some rarely used PGP-compatible software.
- Expires, which specifies the date, when the key expires.
This parameter is optional. If it is not specified, then no expiration date is set.
To generate the key in background, first call BeginGenerate() method of TElPGPSecretKey class.
You will need to pass some of parameters, mentioned above.
After calling BeginGenerate, call AsyncOperationFinished() method of TElPGPSecretKey class from time to time, to find out whether the operation has been completed.
If AsyncOperationFinished() returns true,
call EndGenerate() method and pass the rest of parameters, described above.
After the key is generated, you can add this key to the keyring or save to a separate file.
To access the public key of the generated keypair, use PublicKey property of TElPGPSecretKey class.
|