8

I can't find a single example of how to do this. I have a PGP encrypted XLS file and a PGP key. Here's is my code that returns an empty string:

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

I'm able to decrypt this file in a program called GNU Privacy Assistant on Windows using the same key. Any help is appreciated.

Vincent
  • 16,086
  • 18
  • 67
  • 73

1 Answers1

7

Daiki Ueno, the developer of Ruby gpgme reached out to me on GitHub:

adding decrypted.seek(0) after the line decrypted = ctx.decrypt encrypted_data seems to solve the problem

Vincent
  • 16,086
  • 18
  • 67
  • 73
  • 1
    Thanks for this. Sometimes I feel like the 'E' of GPGME stands for 'Enigmatic' – aidan Sep 22 '14 at 04:16
  • @Vincent what is obj, uid_hint, passphrase_info, prev_was_bad, fd parameters. In my case client has shared public key-private key and encrypted file only – Gupta Feb 22 '18 at 06:59
  • @Vincent, Please provide your help I'm kind of STUCK! in between. – Gupta Feb 22 '18 at 06:59