5

In the previous version of Ubuntu (eg: maverick, natty), I used to do a:

sudo apt-get install gedit-plugins seahorse

to have the ability to encrypt/decrypt file within Gedit after enabling the plugin in the preferences.

But since, Oneiric I've not found a way of achieving this.

And now that I'm running Precise (the LTS version!), I'm a bit disappointed at not being able to do such things.

0

7 Answers 7

4

I had to fight a bit with ryran's example until I got what I needed: encrypt using my GPG key to several people. This is the code to encrypt:

#!/bin/sh
gpg -a -e -r [email protected] -r [email protected] --no-tty -

And to decrypt:

#!/bin/sh
gpg -d --no-tty - 2> /dev/null

And set input to "current document" and output to "replace current document" in both cases.

2

Try Geany, with the PGP plugin. Geany is a lightweight gtk+ based editor, with excellent support.

sudo apt-get install geany geany-plugin-pg
2

Some autopromotion/request for feedback: http://pietrobattiston.it/gedit-crypto

(notice I developed this also because I was not able to use the "External tools" method above without including in clear the password for my key - which I didn't want to).

2
  • +1 for the effort, but it tells me gedit-crypto-plugin breaks gedit (<< 3.12) gedit (version 3.10.4-0ubuntu4) is present and installed. What version of Ubuntu is it designed for? I am on 2014.04. Sep 4, 2014 at 1:00
  • 1
    In the page I linked, you can see "In particular, current versions need gedit 3.12 or later; if you're using a previous version of gedit, download version 0.3 of gedit-crypto." - this is the version you need. Sep 9, 2014 at 16:59
2

Another one that uses the agent and supports entering E-Mail for asymmetric encryption:

#!/bin/bash

mail=$(zenity --entry --text="Enter E-Mail")
gpg -a -e --no-tty -r "$mail" --use-agent -

And decryption:

#!/bin/bash

gpg --no-tty --use-agent -
1

Pipe's link (in the comments) gives the run-down.
You need to add entries under "Manage External Tools" to do this.. for now. You can even add keyboard shortcuts. What the link doesn't mention (as far as I saw) is that you need to install gnupg-agent to be able to enter passphrases.

Here's an example. Create a new action and call it symmetric encrypt:

gpg --use-agent --symmetric 2>/dev/null

Tweak the other options to your liking (you can make it so all the text in the whole window is automatically selected and replaced, you can make the output pop up in a bottom pane, etc.

Note: If you install gnupg2 instead of gnupg-agent, and then start your command-lines with gpg2 instead of gpg, you can take advantage of gpg2's cooler [integrated] agent.

1

Just expanding on @Ignacio solution (which works), I found annoying that if you encrypt twice (or decrypt), it breaks things... so I am running this with an extra care for the state of the encryption on the document:

Encrypt

#!/bin/bash
stdin=$(cat)

if [ ! "${stdin:0:27}" == "-----BEGIN PGP MESSAGE-----"  ]; then 
    echo "$stdin" | gpg -a -e -r [email protected] --no-tty -
else
    echo "$stdin"
fi

Decrypt

#!/bin/bash
stdin=$(cat)

if [ "${stdin:0:27}" == "-----BEGIN PGP MESSAGE-----"  ]; then 
    echo "$stdin" | gpg -d --no-tty - 2> /dev/null
else
    echo "$stdin"
fi

Assuming the settings:

  • Save - Nothing
  • Input - Current document
  • Output - Replace current document
  • Applicability - All documents / All languages

Then you place a shortcut like Ctrl+Shift+D (decrypt) and Ctrl+Shift+E (encrypt), and you are good to go.

-4

April 2023 updated solution !

Encrypt with gedit, the easy way...

  1. install seahorse plugin:

    sudo apt-get install gedit-plugins seahorse
    
  2. open gedit

  3. click "text editor" menu (left side)

  4. click "manage external tools" option

     screenshot

  5. click + to create (add) a new gedit "script" (a.k.a "tool")

  6. write your code (or copy mine based on "openssl") for encrypt (or decrypt)

    note: for each "tool" you need an additional script

     screenshot

    6.1.- my code for encrypt:

     openssl enc -e -pbkdf2 -aes256 -base64 \
     -pass "pass:$(zenity --entry \
     --title="encrypt" --text="create password")";
    

    6.2.- my code for decrypt:

     openssl enc -d -pbkdf2 -aes256 -base64 \
     -pass "pass:$(zenity --entry \
     --title="decrypt" --text="password")";
    
  7. configure each of the previous "tools" input/output selecting the correct options for "selected" or "document" type of use

     screenshot


to execute the scripts (tools): open any document text in gedit and try clicking the (3horizontal bars) menu (right side) then click option "tools/external tools" then click your encrypt script... (if you choose "selected" in step 7 the you need to select some section of the text before executing the encryption or decryption

references:

from "gnome.org" : gedit plugins externaltools

from "dev.to" : testing externaltools

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .