【问题标题】:How could I encrypt a file_path with ruby-gpgme?如何使用 ruby​​-gpgme 加密 file_path?
【发布时间】:2017-10-02 14:37:42
【问题描述】:

我使用了以下模块

https://github.com/ueno/ruby-gpgme

而我的加密代码库是这样的:

  def encrypt_sign(
    plaintext,
    recipient_pubkey,
    sender_privkey,
    binary: nil,
    password: nil
  )
    in_a_directory(binary) do
      options = pinentry_mode(password)

      GPGME::Ctx.new(options) do |ctx|
        import(sender_privkey)  
        import(recipient_pubkey)

        ctx.add_signer(*(find(sender_privkey, :secret)))
        ctx.encrypt_sign(
          find(recipient_pubkey, :public),
          data(plaintext),
          data,
          GPGME::ENCRYPT_ALWAYS_TRUST
        ).to_s
      end
    end
  end

我不知道如何输入文件路径而不是纯文本文件。

感谢任何建议。

【问题讨论】:

    标签: ruby encryption gnupg gpgme


    【解决方案1】:

    密码学上下文中的“明文”不是指实际文本,而是指您要加密的常规数据。因此,只需将文件内容传递为plaintext

    encrypt_sign(File.read(file_path), recipient_pubkey, ...)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-18
      相关资源
      最近更新 更多