我找不到一个例子来说明如何做到这一点。我有一个PGP加密的XLS文件和一个PGP密钥。下面是返回空字符串的代码:
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我能够使用相同的密钥在Windows上名为GNU隐私助理的程序中解密该文件。任何帮助都是非常感谢的。
发布于 2012-04-11 02:24:00
Ruby的开发者Daiki通过GitHub联系了我:
在行后添加
decrypted.seek(0)似乎解决了
的问题
https://stackoverflow.com/questions/10092184
复制相似问题