0

I was trying to generate a key with python-gnupg library. My code is running perfectly but it is not creating a key.

Code:

import gnupg

gpg = gnupg.GPG()

# generate key
input_data = gpg.gen_key_input(
    name_real='name',
    name_email='name@email.com',
    passphrase='passphrase',
    key_type='EDDSA', 
    key_curve='ed25519',
    key_usage='sign encrypt',
    subkey_type='ecdh',
    subkey_curve='cv25519',
    expire_date='2y'
)
key = gpg.gen_key(input_data)
print(key)

I have found that if I remove "key_usage" it generates the key, but I want to generate the key with "key_usage".

I have followed this link to generate a key: https://gnupg.readthedocs.io/en/latest/.

I will be happy to hear your suggestions.

  • You don't appear to be doing any error checking. Look at the values of things like `key.returncode` and `key.stderr`. – larsks Feb 21 '23 at 00:33
  • In returncode I get `2`, and in stderr I get `gpg: -:6: specified Key-Usage not allowed for algo 22 [GNUPG:] KEY_NOT_CREATED`. However before I delete gnupg, this code was working properly. I don't know what happened. – Oguz Gokyuzu Feb 21 '23 at 01:36
  • It looks like the key type you've chosen can only be used for signing, not for encryption. – larsks Feb 21 '23 at 01:40
  • It supposed to work. If I delete 'key_usage', gnupg generates a key with encryption, signing and authentication. – Oguz Gokyuzu Feb 21 '23 at 11:32

0 Answers0