From: Daiki Ueno Date: 2010-01-17T21:59:48+09:00 Subject: Re: GPGME gem - cannot figure out how to decrypt data --=-=-= Daniel Frank writes: >> Could you provide actual input args to passfunc, that can be inspected >> with: >> > def passfunc(*args) > p args > puts "Passphrase callback" > SMGConfig.instance.gpg_password > end > > Relevant part of the output: > decrypting > [] > Passphrase callback > > If I interpret this right, [] means that there's an empty array, which > means no arguments? You are right, but the result looks strange. Could you try the attached script, which decrypts a file specified as the first command line argument? I've confirmed it working with gpgme-1.0.8 (gem), ruby-1.8.7, and gpg 1.4.10, as follows: $ echo this is a test | gpg --encrypt -r 37ED8A79 > test.gpg $ ruby1.8 -rubygems decrypt.rb test.gpg Plaintext: this is a test --=-=-= Content-Type: application/x-ruby Content-Disposition: attachment; filename=decrypt.rb #!/usr/bin/env ruby require 'gpgme' # If you do not have gpg-agent installed, comment out the following # and set it as :passphrase_callback. # def passfunc(hook, uid_hint, passphrase_info, prev_was_bad, fd) $stderr.write("Passphrase for #{uid_hint}: ") $stderr.flush begin system('stty -echo') io = IO.for_fd(fd, 'w') io.puts(gets) io.flush ensure (0 ... $_.length).each do |i| $_[i] = ?0 end if $_ system('stty echo') end $stderr.puts end unless ENV['GPG_AGENT_INFO'] $stderr.puts("gpg-agent is not running. See the comment in #{$0}.") exit(1) end plain = GPGME::decrypt(ARGF, { :passphrase_callback => method(:passfunc) }) puts("Plaintext:\n#{plain}") --=-=-= Regards, -- Daiki Ueno --=-=-=--