Implementing gpg Encryption in Ruby

Trying to convert some old shell / unix scripts to Ruby.

I have the following encryption for a file executed with the gpg tool on Unix. I can transfer the recipient key, the file I want to encrypt, and outfile for pgp encryption.

gpg --recipient "$my_recipient_key" \ --encrypt "$my_file" \ --output "$my_outfile" \ --always-trust \ --compress-algo zip 

What is Ruby equivalent for simple encryption as stated above?

After some digging, I see:

  • OpenPGP is popular, but there is no documentation on the RubyGems website, and rare examples elsewhere.
  • gpgme seems popular and promising. However, I will be honest, I'm new to Ruby and clicking on the documentation (see the Link) leaves me a little confused about where to start (for example, a good example will be nice).
  • I also see other smaller jewelry and libraries that were created by users, but I am limited to using certified gems from the rubyGems database, as this is used for official use.

Thanks!

+6
source share
1 answer

I recently used gpgme. The code for encrypting the file was as follows:

 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 

You might want to find out that there are no "certified" ones on the rubigems - everyone can place a gem there (and this takes all 3 minutes)

+9
source

Source: https://habr.com/ru/post/947425/


All Articles