Skip to content
This repository has been archived by the owner. It is now read-only.
[Retired] RSA.rb is a pure-Ruby implementation of the RSA encryption algorithm and the PKCS#1 cryptography standard.
Branch: master
Clone or download

RSA.rb: RSA Encryption for Ruby

RSA.rb is a Ruby library that implements the RSA encryption algorithm and the PKCS#1 cryptography standard.


  • 100% free and unencumbered public domain software.
  • Implements the PKCS#1 data conversion primitives (I2OSP and OS2IP).
  • Implements the PKCS#1 encryption/decryption primitives (RSAEP and RSADP).
  • Implements the PKCS#1 signature primitives (RSASP1 and RSAVP1).
  • Implements RSA key pair generation using Ruby's OpenSSL standard library.
  • Compatible with Ruby 1.9.1+ and JRuby 1.5.0+.
  • Compatible with older Ruby versions with the help of the Backports gem.


require 'rsa'

Generating a new RSA key pair

key_pair = RSA::KeyPair.generate(128)

Encrypting a plaintext message

ciphertext = key_pair.encrypt("Hello, world!")

Decrypting a ciphertext message

plaintext = key_pair.decrypt(ciphertext)


  • {RSA::KeyPair}
  • {RSA::Key}
  • {RSA::PKCS1}



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

% [sudo] gem install rsa             # Ruby 1.9.1+
% [sudo] gem install backports rsa   # Ruby 1.8.x


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



Refer to the accompanying {file:CREDITS} file.


  • 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, VERSION or AUTHORS files. If you need to change them, do so on your private branch only.
  • Do feel free to add yourself to the CREDITS file and the corresponding list in the the README. Alphabetical order applies.
  • 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.


This is free and unencumbered public domain software. For more information, see or the accompanying {file:UNLICENSE} file.

You can’t perform that action at this time.