OpenPGP.rb is a pure-Ruby implementation of the OpenPGP Message Format (RFC 4880).
Pull request Compare This branch is 33 commits ahead, 2 commits behind dryruby:master.
Latest commit 99a0e41 Jul 23, 2011 @singpolyma Merge branch 'keysign'
* keysign:
  keygen example script
  add bn2bin and egcd algorithms
  Add OpenSSL wrapper for signing keys
  Add ability to sign keys
  UserID packet body
  better exception message
  store hash_head unpacked
  Refactor PublicKey, Implement SecretKey
  use bitlength, not *8
  order hashed subpackets correctly
  Implement Features
  Implement KeyFlags
  Support leading 0s
Failed to load latest commit information.
spec Fixed some Ruby 1.9 compatibility issues relating to string encodings. Jul 3, 2010
.gitignore Updated .gitignore. Jul 3, 2010
.yardopts Updated YARD documentation settings. Jul 3, 2010
CONTRIBUTORS I am a contributor Aug 12, 2010
README Changed README format from RDoc to Markdown. Dec 20, 2009
Rakefile Updated the Rakefile. Jun 18, 2010

OpenPGP.rb: OpenPGP for Ruby

This is a pure-Ruby implementation of the OpenPGP Message Format (RFC 4880).

About OpenPGP

OpenPGP is the most widely-used e-mail encryption standard in the world. It is defined by the OpenPGP Working Group of the Internet Engineering Task Force (IETF) Proposed Standard RFC 4880. The OpenPGP standard was originally derived from PGP (Pretty Good Privacy), first created by Phil Zimmermann in 1991.


  • Encodes and decodes ASCII-armored OpenPGP messages.
  • Parses OpenPGP messages into their constituent packets.
    • Supports both old-format (PGP 2.6.x) and new-format (RFC 4880) packets.
  • Includes a GnuPG wrapper for features that are not natively supported.


require 'rubygems'
require 'openpgp'

Decoding an ASCII-armored message

require 'open-uri'
text = open('').read

msg = OpenPGP::Message.parse(OpenPGP.dearmor(text))

Generating a new keypair

gpg = => '~/.gnupg')
key_id = gpg.gen_key({
  :key_type      => 'DSA',
  :key_length    => 1024,
  :subkey_type   => 'ELG-E',
  :subkey_length => 1024,
  :name          => 'J. Random Hacker',
  :comment       => nil,
  :email         => '',
  :passphrase    => 'secret passphrase',



  • Ruby (>= 1.8.7) or (>= 1.8.1 with [Backports][])
  • Open4 (>= 1.0.1)


The recommended installation method is via RubyGems. To install the latest official release of OpenPGP.rb, do:

% [sudo] gem install openpgp             # Ruby 1.8.7+ or 1.9.x
% [sudo] gem install backports openpgp   # Ruby 1.8.1+


To get a local working copy of the development repository, do:

% git clone git://

Alternatively, you can download the latest development version as a tarball as follows:

% wget





  • Do your best to adhere to the existing coding conventions and idioms.
  • Don't use hard tabs, and don't leave trailing whitespace on any line.
  • Do document every method you add using YARD annotations. Read the tutorial or just look at the existing code for examples.
  • Don't touch the .gemspec or VERSION files. If you need to change them, do so on your private branch only.
  • Do feel free to add yourself to the CONTRIBUTORS file and the corresponding list in the the README. Alphabetical order applies.
  • Don't touch the AUTHORS file. If your contributions are significant enough, be assured we will eventually add you in there.
  • Do note that in order for us to merge any non-trivial changes (as a rule of thumb, additions larger than about 15 lines of code), we need an explicit public domain dedication on record from you.


OpenPGP.rb is free and unencumbered public domain software. For more information, see or the accompanying UNLICENSE file.