在下面的示例中,我尝试了password和passphrase。这两个似乎都不允许我在没有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如果有人能向我解释一下对我的代码进行哪些更改会有帮助,我正在倾听。
解决方案:我发现拼音提示是因为GPG2与GPG1.4。我降级到了GPG1.4,现在它似乎可以工作了。
如果有人知道如何让GPG2工作,请发表评论
谢谢
发布于 2017-07-18 22:17:59
在GPG2上提供pinentry_mode: GPGME::PINENTRY_MODE_LOOPBACK选项对我很有效:
GPGME::Ctx.new(
pinentry_mode: GPGME::PINENTRY_MODE_LOOPBACK,
passphrase_callback: method(:passfunc)
)https://stackoverflow.com/questions/21554292
复制相似问题