在Ruby中实现gpg加密
发布时间:2020-12-16 23:00:08 所属栏目:百科 来源:网络整理
导读:试图将一些旧的 shell / unix脚本转换为 Ruby. 我对通过Unix中的gpg工具完成的文件进行了以下加密.我可以传入收件人密钥,我要加密的文件,以及pgp的outfile加密东西. gpg --recipient "$my_recipient_key" --encrypt "$my_file" --output "$my_outfile"
试图将一些旧的
shell / unix脚本转换为
Ruby.
我对通过Unix中的gpg工具完成的文件进行了以下加密.我可以传入收件人密钥,我要加密的文件,以及pgp的outfile加密东西. gpg --recipient "$my_recipient_key" --encrypt "$my_file" --output "$my_outfile" --always-trust --compress-algo zip 与上面的简单加密相比,Ruby相当于什么? 做了一些挖掘后,我看到: > OpenPGP很受欢迎,但RubyGems网站上没有文档,其他地方也很少有很好的例子. 谢谢! 解决方法
我最近用过gpgme.加密文件的代码如下所示
GPGME::Key.import(File.open(path_to_key)) #only needed if the key has not been imported previously crypto = GPGME::Crypto.new :always_trust => true File.open(path_to_encrypt) do |in_file| File.open(output_path,'wb') do |out_file| crypto.encrypt in_file,:output => out_file,:recipients => "foo@example.com" end end 你可能想知道什么没有“认证”关于什么是rubygems – 任何人都可以在那里发布一个宝石(并且需要3分钟才能完成) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |