- key_type: type of key
- key _length: length of the key in bits
- name_real: real name
- name_comment : comment
- name_email : email-id
- passphrase: passphrase of the private key
Exporting GPG Keys:
Use the export_keys() method to export public and private keys. It takes the following parameters:
- keyids: a key ID or fingerprint
- secret: True if it is a private key
- subkey: True if it is a subkey
>>> public_keys = gpg.export_keys(keyids) >>> private_keys = gpg.export_keys(keyids, True)
Importing GPG Keys:
You can import keys using the following methods:
>>> import_result = gpg.import_keys(key_data)
key_data is an ASCII string of the public key. It can be obtained by the method export_keys() or from a key server.
To receive a public key from a key server, use the following method:
>>> import_result = gpg.recv_keys('server-name', 'keyid1', 'keyid2', ...)
Listing GPG Keys:
You can list the keys in the keyring using the following method:
>>> public_keys = gpg.list_keys()
Use the parameter True to list private keys.
>>> private_keys = gpg.list_keys(True)
Encryption And Decryption Using GPG Keys:
To encrypt data using GPG in Python, use the following method:
>>> gpg.encrypt(data, recipients)
This method takes the following arguments: …










































0 Comments