Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I encrypt data with a specific Key? #109

Open
sumdog opened this issue Jan 14, 2018 · 1 comment
Open

How do I encrypt data with a specific Key? #109

sumdog opened this issue Jan 14, 2018 · 1 comment

Comments

@sumdog
Copy link

sumdog commented Jan 14, 2018

I've been looking through the documentation and I'm a big confused by this. The decrypt function is pretty straight forward and launches my pgp agent to prompt for a password and automatically chose the correct decryption key.

I'm confused about the reverse. How do I sign data with a specific key? I can run GPGME::Key.find(:secret, '4F480261701CB81FB00334017322917262CCC1E5') to find the key in my local store that I want to sign my data with. The documentation around decrypt just says you need to run Keys.import first. I tried the following:

key = GPGME::Key.find(:secret, '4F480261701CB81FB00334017322917262CCC1E5').first
GPGME::Key.import(key)
#<GPGME::ImportResult:0x00000000b69360 @considered=1, @no_user_id=0, @imported=0, @imported_rsa=0, @unchanged=1, @new_user_ids=0, @new_sub_keys=0, @new_signatures=0, @new_revocations=0, @secret_read=0, @secret_imported=0, @secret_unchanged=0, @not_imported=0, @imports=[#<GPGME::ImportStatus:0x00000000b69310 @fpr="4F480261701CB81FB00334017322917262CCC1E5", @result=0, @status=0>]>

But it doesn't appear to do anything. If I run encrypt using the e-mail the key is for, I get the following:

crypt.encrypt "something", :signer=>"[email protected]"
GPGME::Error::UnusablePublicKey: GPGME::Error::UnusablePublicKey

Also, it doesn't appear that I can just use the short identifier for the key in Key.find, I have to use the whole thing.

@adam-haku
Copy link

I was getting the same error. I think it was caused by not trusting the key when it was imported (https://www.gnupg.org/gph/en/manual/x56.html). Passing the :always_trust option allows you to circumvent it.

crypto.encrypt("Hello",:recipients => "[email protected]",:always_trust => true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants