【问题标题】:How to decrypt PGP encrypted file with Ruby gpgme如何使用 Ruby gpgme 解密 PGP 加密文件
【发布时间】:2012-04-10 15:58:02
【问题描述】:

我找不到一个如何做到这一点的例子。我有一个 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 Privacy Assistant 的程序中使用相同的密钥解密此文件。任何帮助表示赞赏。

【问题讨论】:

    标签: ruby encryption gnupg pgp gpgme


    【解决方案1】:

    Ruby gpgme 的开发者 Daiki Ueno 在 GitHub 上联系了我:

    decrypted = ctx.decrypt encrypted_data 行之后添加decrypted.seek(0) 似乎可以解决问题

    【讨论】:

    • 谢谢。有时我觉得 GPGME 的“E”代表“神秘”
    • @Vincent 什么是 obj、uid_hint、passphrase_info、prev_was_bad、fd 参数。在我的情况下,客户端仅共享公钥-私钥和加密文件
    • @Vincent,请提供您的帮助,我有点卡住了!介于两者之间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    • 2012-04-29
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多