• What’s this?

Ruby-GPGME is a Ruby language binding of GPGME (GnuPG Made Easy).

  • Requirements

  • Ruby 1.8 or later

  • GPGME 1.1.2 or later

  • gpg-agent (optional, but recommended)

  • Installation

$ ruby extconf.rb
$ make
$ make install
  • Examples

examples/genkey.rb  Generate a key pair in your keyring.
examples/keylist.rb List your keyring like gpg --list-keys.
examples/roundtrip.rb  Encrypt a plain text and then decrypt it.
examples/sign.rb  Create a clear text signature.
examples/verify.rb  Verify a clear text signature given from stdin.
  • API

Ruby-GPGME provides 3 levels of API. The highest level API is close to the command line interface of GnuPG. The lowest level API is close to the C interface of GPGME.

** The highest level API

For example, to create a cleartext signature of the plaintext from stdin can be written as follows.

$ ruby -rgpgme -e 'GPGME.clearsign($stdin, $stdout)'

** The lowest level API

The same example can be rewritten in the lowest level API as follows.

$ ruby -rgpgme -e "ret = Array.new\nGPGME::gpgme_new(ret)\nctx = ret.shift\nGPGME::gpgme_data_new_from_fd(ret, 0)\nplain = ret.shift\nGPGME::gpgme_data_new_from_fd(ret, 1)\nsig = ret.shift\nGPGME::gpgme_op_sign(ctx, plain, sig, GPGME::SIG_MODE_CLEAR)\n"  

As you see, it’s much harder to write a program in this API than the highest level API. However, if you are already familier with the C interface of GPGME and/or want to control detailed behavior of GPGME, it might be useful.

** The mid level API

There is another API which looks object-oriented. It’s easier to use than the lowest level API though, you should first consult the highest level API.

$ ruby -rgpgme -e "ctx = GPGME::Ctx.new\nplain = GPGME::Data.from_io($stdin)\nsig = GPGME::Data.from_io($stdout)\nctx.sign(plain, sig, GPGME::SIG_MODE_CLEAR)\n"