首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GPGME密码提示问题(Ruby)

GPGME密码提示问题(Ruby)
EN

Stack Overflow用户
提问于 2014-02-04 21:47:11
回答 1查看 1.4K关注 0票数 4

在下面的示例中,我尝试了password和passphrase。这两个似乎都不允许我在没有openpgp框提示输入密码的情况下运行代码,消息如下:

Pinentry Mac“请输入密码以解锁OpenPGP证书的密钥”

我需要更改什么才能让我的代码在没有提示的情况下运行?我知道我的密码在代码中是正确的。

我试过了:

代码语言:javascript
复制
ctx = GPGME::Ctx.new :password=> 'password'

还有这个:

代码语言:javascript
复制
ctx = GPGME::Ctx.new :passphrase_callback => method(:passfunc)

但这两种方法似乎都不起作用。任何建议都是值得感谢的。

代码语言:javascript
复制
  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工作,请发表评论

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-07-18 22:17:59

在GPG2上提供pinentry_mode: GPGME::PINENTRY_MODE_LOOPBACK选项对我很有效:

代码语言:javascript
复制
GPGME::Ctx.new(
  pinentry_mode: GPGME::PINENTRY_MODE_LOOPBACK,
  passphrase_callback: method(:passfunc)
)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21554292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档