Skip to content

Instantly share code, notes, and snippets.

@Madh93
Last active March 24, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Madh93/e2e9c04b7ac1fde33046ff8855e67150 to your computer and use it in GitHub Desktop.
Save Madh93/e2e9c04b7ac1fde33046ff8855e67150 to your computer and use it in GitHub Desktop.
GPG encryption and decryption for lazy people, like me
[Nemo Action]
Name=Decrypt
Comment=Decrypt files
Exec=/usr/local/bin/gpg-decrypt %F
Icon-Name=seahorse
Selection=notnone
Extensions=gpg
Quote=double
Terminal=true
#! /usr/bin/env ruby
# NAME : GPG Decryption Tool
# DESCRIPTION : Decrypt all .gpg files passed
# AUTHOR : Madh93 (Miguel Hernandez)
# VERSION : 0.0.1
# LICENSE : GNU General Public License v3
# USAGE : ruby gpg-decrypt.rb [files]
require 'io/console'
require 'ruby_gpg'
# Get files to decrypt
if (files = ARGV.grep(/\.gpg$/)).empty?
puts 'No valid file passed!'
exit
end
# Ask for passphrase
passphrase = nil
passphrase ||= STDIN.getpass('Passphrase: ').chomp
# Decrypt the files
files.each do |f|
next unless File.file?(f)
basefile = File.basename(f, '.gpg')
if File.file?(basefile)
puts "File: '#{basefile}' already exists. Skipping..."
else
RubyGpg.decrypt(f, passphrase)
puts "File '#{f}' decrypted."
end
end
puts 'All done!'
[Nemo Action]
Name=Cifrar
Comment=Cifrar archivos
Exec=/usr/local/bin/gpg-encrypt %F
Icon-Name=seahorse
Selection=notnone
Extensions=nodirs
Quote=double
#! /usr/bin/env ruby
# NAME : GPG Encryption Tool
# DESCRIPTION : Encrypt all files passed
# AUTHOR : Madh93 (Miguel Hernandez)
# VERSION : 0.0.1
# LICENSE : GNU General Public License v3
# USAGE : ruby gpg-encrypt.rb [files]
require 'ruby_gpg'
# Get files to encrypt
if (files = ARGV.grep_v(/\.gpg$/)).empty?
puts 'No valid file passed!'
exit
end
# Ask for recipient
recipient = nil
unless recipient
print 'Recipient: '
recipient = $stdin.gets.chomp
end
# Encrypt the files
files.each do |f|
next unless File.file?(f)
if File.file?("#{f}.gpg")
puts "File: '#{f}.gpg' already exists. Skipping..."
else
RubyGpg.encrypt(f, recipient)
puts "File '#{f}' encrypted."
end
end
puts 'All done!'

GPG encryption and decryption for lazy people

Requirements

gem install ruby_gpg

How to use

To encrypt files:

ruby gpg-encrypt.rb file1.jpg file2.odt

To decrypt files:

ruby gpg-encrypt.rb file1.jpg.gpg file2.odt.gpg

I recommend add these scripts into /usr/local/bin (it must be declared in $PATH):

mv gpg-encrypt.rb /usr/local/bin/gpg-encrypt && chmod +x /usr/local/bin/gpg-encrypt
mv gpg-decrypt.rb /usr/local/bin/gpg-decrypt && chmod +x /usr/local/bin/gpg-decrypt

Nemo actions (Optional)

To use these scripts through Nemo file manager (default file manager in Cinnamon desktop environment), it's only necessary add them into /home/$USER/.local/share/nemo/actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment