python-gnupg No valid data found with import_keys

285 Views Asked by At

I'm trying to read a public key file so I can encrypt a file. I'm using the following code:

import gnupg
import os
import pprint

key_file = '/Users/me/Downloads/id_rsa_test.txt'
gpg = gnupg.GPG()

key_data = open(key_file, encoding="utf-8").read()
key_data
import_result = gpg.import_keys(key_file)
pprint(import_result.results)

but I see the below:

[{'fingerprint': None, 'problem': '0', 'text': 'No valid data found'}]

In the docs it says 'get the key data as an ASCII string' does this mean I should covert the file contents to string? I've tried this but it didn't work:

f = open(key_file, 'r')
f
key_file = f.read()

I've also tried this, by just importing as a string var:

private_secret = """
-----BEGIN OPENSSH PRIVATE KEY----- 
  <KEY CHARACTERS> 
   """
-----END OPENSSH PRIVATE KEY-----

I believe the issue is that I was given an ssh key not a gpg key, but that's what I'm working with. Can I create a new gpg key pair with this ssh key?

Also, I believe its my key because I've tried the secret in this example and it worked with their key: https://github.com/vsajip/python-gnupg/blob/master/test_gnupg.py docs = https://pythonhosted.org/python-gnupg/#importing-and-receiving-keys

0

There are 0 best solutions below