在Ruby中实现gpg加密
正在尝试将一些旧的shell/unix脚本转换为Ruby 我对一个文件进行了以下加密,这是通过Unix中的gpg工具完成的。我可以将收件人密钥、要加密的文件和输出文件传递给pgp加密在Ruby中实现gpg加密,ruby,encryption,gnupg,openpgp,Ruby,Encryption,Gnupg,Openpgp,正在尝试将一些旧的shell/unix脚本转换为Ruby 我对一个文件进行了以下加密,这是通过Unix中的gpg工具完成的。我可以将收件人密钥、要加密的文件和输出文件传递给pgp加密 gpg --recipient "$my_recipient_key" \ --encrypt "$my_file" \ --output "$my_outfile" \ --always-trust \ --compress-algo zip Ruby相当于做上述简单的加密吗 在
gpg --recipient "$my_recipient_key" \
--encrypt "$my_file" \
--output "$my_outfile" \
--always-trust \
--compress-algo zip
Ruby相当于做上述简单的加密吗
在做了一些挖掘之后,我看到:
谢谢 我最近用过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上的内容没有任何“认证”的内容——任何人都可以在那里发布一个gem(这需要3分钟)就像我在5分钟内把这个()拼凑在一起一样!:-)