【发布时间】:2014-02-04 13:47:11
【问题描述】:
在下面的示例中,我尝试了密码和密码。似乎都不允许我在没有提示输入密码的 openpgp 框的情况下运行我的代码,以下消息:
Pinentry Mac "请输入密码以解锁 OpenPGP 证书的密钥"
我需要更改哪些内容才能让我的代码在没有提示的情况下运行?我知道我的密码在代码中是正确的。
我试过了:
ctx = GPGME::Ctx.new :password=> 'password'
还有这个:
ctx = GPGME::Ctx.new :passphrase_callback => method(:passfunc)
但两者似乎都不起作用。任何建议表示赞赏。
def self.passfunc(obj, uid_hint, passphrase_info, prev_was_bad, fd)
io = IO.for_fd(fd, 'w')
io.puts 'password'
io.flush
end
def self.decrypt_file(local_file, decrypted_file = nil)
# Set decrypted file path if one is not provided
decrypted_file = local_file.chomp(File.extname(local_file)) + ".csv" if decrypted_file == nil
encrypted_data = GPGME::Data.new(File.open(local_file))
# Set the password and GPG Key to decryption
ctx = GPGME::Ctx.new :password=> 'password'
# I have tried the passphrase call back
#ctx = GPGME::Ctx.new :passphrase_callback => method(:passfunc)
#KEY= GPGME::Data.new(File.open("key.gpg"))
ctx.import_keys Rebal::Config::KEY
# Decrypt the data
decrypted = ctx.decrypt encrypted_data
decrypted.seek(0)
#Write the data to a file
File.write(decrypted_file, decrypted.read)
#return path
decrypted_file
end
以下链接似乎没有帮助... Using passphrase callback in ruby gpgme 我不确定这个链接指的是什么或它如何解决我的具体问题,但它可能是解决方案...... how to bypass pinentry (passphrase screen) while decrypting a file using gpgme如果有人可以向我解释对我的代码进行哪些更改会有所帮助,我正在倾听。
解决方案:我发现 pinentry 提示是因为 GPG2 与 GPG1.4。我降级到 GPG1.4,现在它似乎可以工作了。
如果有人知道如何让 GPG2 工作,请发表评论
谢谢
【问题讨论】:
-
既然你找到了解决方案,你介意把它写成答案吗?回答自己的问题并没有错。
标签: ruby-on-rails ruby gnupg openpgp