How to decrypt an encrypted PGP file using Ruby gpgme

I can not find a single example of how to do this. I have an encrypted PGP XLS file and a PGP key. Here 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 can decrypt this file in a program called GNU Privacy Assistant on Windows using the same key. Any help is appreciated.

+7
source share
1 answer

Daiki Ueno, a Ruby gpgme developer, handed me on GitHub:

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

+6
source

All Articles