首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用ruby-gpgme加密file_path?

如何使用ruby-gpgme加密file_path?
EN

Stack Overflow用户
提问于 2017-10-02 22:37:43
回答 1查看 58关注 0票数 0

我使用了以下模块

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

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

代码语言:javascript
复制
  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

我不知道如何输入文件路径,而不是明文文件。

任何建议都是值得感谢的。

EN

回答 1

Stack Overflow用户

发布于 2017-10-03 00:51:38

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

代码语言:javascript
复制
encrypt_sign(File.read(file_path), recipient_pubkey, ...)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46527727

复制
相关文章

相似问题

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