Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
This is a mirror of the original gem by Daiki Ueno. GPGME is a Ruby language binding of GPGME (GnuPG Made Easy). GnuPG Made Easy (GPGME) is a library designed to make access to GnuPG easier for applications. It provides a High-Level Crypto API for encryption, decryption, signing, signature verification and key management.
C Ruby
branch: master

README.rdoc

Ruby-GPGME

History behind this fork

This project started as my Ruby Mendicant University. The idea is to give an overhaul to the API of this gem. As a relativelly new developer in the ruby world, I found the documentation not very newbie friendly, and the API somewhat different to the kind I'm used to in the ruby world.

GPG is a very powerful tool, and this gem is implemented using the C bindings, making it very fast, and the only proper way to do it.

My objectives are as follows:

  • Add test coverage of some type.

  • Make documentation a little bit more newbie friendly.

  • Improve the API to be more idiomatic.

Description

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

GnuPG Made Easy (GPGME) is a library designed to make access to GnuPG easier for applications. It provides a High-Level Crypto API for encryption, decryption, signing, signature verification and key management.

Requirements

  • Ruby 1.8 or later

  • GPGME 1.1.2 or later

  • gpg-agent (optional, but recommended)

Installation

$ gem install ruby-gpgme

or

$ 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 three levels of API. The highest level API is close to the command line interface of GnuPG. The mid level API looks object-oriented (or rubyish). 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 and write the result to stdout can be written as follows.

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

The mid level API

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

$ ruby -rgpgme -e <<End
ctx = GPGME::Ctx.new
plain = GPGME::Data.from_io($stdin)
sig = GPGME::Data.from_io($stdout)
ctx.sign(plain, sig, GPGME::SIG_MODE_CLEAR)
End

The lowest level API

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

$ ruby -rgpgme -e <<End
ret = Array.new
GPGME::gpgme_new(ret)
ctx = ret.shift
GPGME::gpgme_data_new_from_fd(ret, 0)
plain = ret.shift
GPGME::gpgme_data_new_from_fd(ret, 1)
sig = ret.shift
GPGME::gpgme_op_sign(ctx, plain, sig, GPGME::SIG_MODE_CLEAR)
End

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 want to control detailed behavior of GPGME, it might be useful.

License

The library itself is licensed under LGPLv2.1+. See the file COPYING.LESSER and each file for copyright and warranty information.

Something went wrong with that request. Please try again.