ruby-gpgme icon indicating copy to clipboard operation
ruby-gpgme copied to clipboard

Decrypt the file using public key only

Open brijeshgpt7 opened this issue 7 years ago • 1 comments

I have an encrypted file with pgp extension that needs to be decrypted using the shared public key. `require 'rubygems' require 'gpgme'

def passfunc(obj, uid_hint, passphrase_info, prev_was_bad, fd) io = IO.for_fd(fd, 'w') io.puts "PASSPHRASE" io.flush end

encrypted_data = GPGME::Data.new(File.open("file.xls.pgp")) key = GPGME::Data.new(File.open("key.txt"))

ctx = GPGME::Ctx.new :passphrase_callback => method(:passfunc) ctx.import_keys key

decrypted = ctx.decrypt encrypted_data

puts decrypted.read`

Error: r/gems/gpgme-2.0.11/lib/gpgme/ctx.rb:385:in `import_keys': Unsupported protocol (GPGME::Error)

brijeshgpt7 avatar Feb 22 '18 07:02 brijeshgpt7

While the error message looks interesting, I don't get what you want to achieve. In public key cryptography, you can't decrypt message with a public key.

ueno avatar Feb 26 '18 09:02 ueno