Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages

Manual Reference Pages  -  CRYPT::RSA (3)

.ds Aq ’


Crypt::RSA - RSA public-key cryptosystem.



    my $rsa = new Crypt::RSA;

    my ($public, $private) =
        $rsa->keygen (
            Identity  => Lord Macbeth <>,
            Size      => 1024, 
            Password  => A day so foul & fair,
            Verbosity => 1,
        ) or die $rsa->errstr();

    my $cyphertext =
        $rsa->encrypt (
            Message    => $message,
            Key        => $public,
            Armour     => 1,
        ) || die $rsa->errstr();

    my $plaintext =
        $rsa->decrypt (
            Cyphertext => $cyphertext,
            Key        => $private,
            Armour     => 1,
        ) || die $rsa->errstr();

    my $signature =
        $rsa->sign (
            Message    => $message,
            Key        => $private
        ) || die $rsa->errstr();

    my $verify =
        $rsa->verify (
            Message    => $message,
            Signature  => $signature,
            Key        => $public
        ) || die $rsa->errstr();


This manual assumes familiarity with public-key cryptography and the RSA algorithm. If you don’t know what these are or how they work, please refer to the sci.crypt FAQ[15]. A formal treatment of RSA can be found in [1].


Crypt::RSA is a pure-perl, cleanroom implementation of the RSA public-key cryptosystem. It uses Math::Pari(3), a perl interface to the blazingly fast PARI library, for big integer arithmetic and number theoretic computations.

Crypt::RSA provides arbitrary size key-pair generation, plaintext-aware encryption (OAEP) and digital signatures with appendix (PSS). For compatibility with SSLv3, RSAREF2, PGP and other applications that follow the PKCS #1 v1.5 standard, it also provides PKCS #1 v1.5 encryption and signatures.

Crypt::RSA is structured as bundle of modules that encapsulate different parts of the RSA cryptosystem. The RSA algorithm is implemented in Crypt::RSA::Primitives(3). Encryption schemes, located under Crypt::RSA::ES, and signature schemes, located under Crypt::RSA::SS, use the RSA algorithm to build encryption/signature schemes that employ secure padding. (See the note on Security of Padding Schemes.)

The key generation engine and other functions that work on both components of the key-pair are encapsulated in Crypt::RSA::Key(3). Crypt::RSA::Key::Public(3) & Crypt::RSA::Key::Private(3) provide mechanisms for storage & retrival of keys from disk, decoding & encoding of keys in certain formats, and secure representation of keys in memory. Finally, the Crypt::RSA module provides a convenient, DWIM wrapper around the rest of the modules in the bundle.


It has been conclusively shown that textbook RSA is insecure[3,7]. Secure RSA requires that plaintext is padded in a specific manner before encryption and signing. There are four main standards for padding: PKCS #1 v1.5 encryption & signatures, and OAEP encryption & PSS signatures. Crypt::RSA implements these as four modules that provide overloaded encrypt(), decrypt(), sign() and verify() methods that add padding functionality to the basic RSA operations.

Crypt::RSA::ES::PKCS1v15(3) implements PKCS #1 v1.5 encryption, Crypt::RSA::SS::PKCS1v15(3) implements PKCS #1 v1.5 signatures, Crypt::RSA::ES::OAEP(3) implements Optimal Asymmetric Encryption and Crypt::RSA::SS::PSS(3) Probabilistic Signatures.

PKCS #1 v1.5 schemes are older and hence more widely deployed, but PKCS #1 v1.5 encryption has certain flaws that make it vulnerable to chosen-cyphertext attacks[9]. Even though Crypt::RSA works around these vulnerabilities, it is recommended that new applications use OAEP and PSS, both of which are provably secure[13]. In any event, Crypt::RSA::Primitives (without padding) should never be used directly.

That said, there exists a scheme called Simple RSA[16] that provides security without padding. However, Crypt::RSA doesn’t implement this scheme yet.


<B>B>new()<B>B> The constructor. When no arguments are provided, new() returns an object loaded with default values. This object can be customized by specifying encryption & signature schemes, key formats and post processors. For details see the section on <B>Customizing the Crypt::RSA objectB> later in this manpage.
<B>B>keygen()<B>B> keygen() generates and returns an RSA key-pair of specified bitsize. keygen() is a synonym for Crypt::RSA::Key::generate(). Parameters and return values are described in the Crypt::RSA::Key(3) manpage.
<B>B>encrypt()<B>B> encrypt() performs RSA encryption on a string of arbitrary length with a public key using the encryption scheme bound to the object. The default scheme is OAEP. encrypt() returns cyphertext (a string) on success and undef on failure. It takes a hash as argument with following keys:
<B>MessageB> An arbitrary length string to be encrypted.
<B>KeyB> Public key of the recipient, a Crypt::RSA::Key::Public(3) or compatible object.
<B>ArmourB> A boolean parameter that forces cyphertext through a post processor after encrpytion. The default post processor is Convert::ASCII::Armour(3) that encodes binary octets in 6-bit clean ASCII messages. The cyphertext is returned as-is, when the Armour key is not present.
<B>B>decrypt()<B>B> decrypt() performs RSA decryption with a private key using the encryption scheme bound to the object. The default scheme is OAEP. decrypt() returns plaintext on success and undef on failure. It takes a hash as argument with following keys:
<B>CyphertextB> Cyphertext of arbitrary length.
<B>KeyB> Private key, a Crypt::RSA::Key::Private(3) or compatible object.
<B>ArmourB> Boolean parameter that specifies whether the Cyphertext is encoded with a post processor.
<B>B>sign()<B>B> sign() creates an RSA signature on a string with a private key using the signature scheme bound to the object. The default scheme is PSS. sign() returns a signature on success and undef on failure. It takes a hash as argument with following keys:
<B>MessageB> A string of arbitrary length to be signed.
<B>KeyB> Private key of the sender, a Crypt::RSA::Key::Private(3) or compatible object.
<B>ArmourB> A boolean parameter that forces the computed signature to be post processed.
<B>B>verify()<B>B> verify() verifies an RSA signature with a public key using the signature scheme bound to the object. The default scheme is PSS. verify() returns a true value on success and undef on failure. It takes a hash as argument with following keys:
<B>MessageB> A signed message, a string of arbitrary length.
<B>KeyB> Public key of the signer, a Crypt::RSA::Key::Public(3) or compatible object.
<B>SignB> A signature computed with sign().
<B>ArmourB> Boolean parameter that specifies whether the Signature has been post processed.


Apart from Crypt::RSA, the following modules are intended for application developer and end-user consumption:
<B>Crypt::RSA::KeyB> RSA key pair generator.
<B>Crypt::RSA::Key::PublicB> RSA Public Key Management.
<B>Crypt::RSA::Key::PrivateB> RSA Private Key Management.
<B>Crypt::RSA::ES::OAEPB> Plaintext-aware encryption with RSA.
<B>Crypt::RSA::SS::PSSB> Probabilistic Signature Scheme based on RSA.
<B>Crypt::RSA::ES::PKCS1v15B> PKCS #1 v1.5 encryption scheme.
<B>Crypt::RSA::SS::PKCS1v15B> PKCS #1 v1.5 signature scheme.


A Crypt::RSA object can be customized by passing any of the following keys in a hash to new(): ES to specify the encryption scheme, SS to specify the signature scheme, PP to specify the post processor, and KF to specify the key format. The value associated with these keys can either be a name (a string) or a hash reference that specifies a module name, its constructor, and constructor arguments. For example:

    my $rsa = new Crypt::RSA ( ES => OAEP );


    my $rsa = new Crypt::RSA ( ES => { Module => Crypt::RSA::ES::OAEP } );

A module thus specified need not be included in the Crypt::RSA bundle, but it must be interface compatible with the ones provided with Crypt::RSA.

As of this writing, the following names are recognised:
<B>ESB> (Encryption Scheme)

    OAEP, PKCS1v15

<B>SSB> (Signature Scheme)

    PSS, PKCS1v15

<B>KFB> (Key Format)

    Native, SSH

<B>PPB> (Post Processor)



All modules in the Crypt::RSA bundle use a common error handling method (implemented in Crypt::RSA::Errorhandler(3)). When a method fails it returns undef and calls $self->error() with the error message. This error message is available to the caller through the errstr() method. For more details see the Crypt::RSA::Errorhandler(3) manpage.


Vipul Ved Prakash, <>


Thanks to Ilya Zakharevich for help with Math::Pari, Benjamin Trott for several patches including SSH key support, Gene\k:`che Ramanoudjame for extensive testing and numerous bug reports, Shizukesa on #perl for suggesting the error handling method used in this module, and Dave Paris for good advice.


Copyright (c) 2000-2008, Vipul Ved Prakash. This code is free software; it is distributed under the same license as Perl itself.

I have received requests for commercial licenses of Crypt::RSA, from those who desire contractual support and indemnification. I’d be happy to provide a commercial license if you need one. Please send me mail at with the subject Crypt::RSA license. Please don’t send me mail asking if you need a commercial license. You don’t, if Artistic of GPL suit you fine.


Crypt::RSA::Primitives(3), Crypt::RSA::DataFormat(3), Crypt::RSA::Errorhandler(3), Crypt::RSA::Debug(3), Crypt::Primes(3), Crypt::Random(3), Crypt::CBC(3), Crypt::Blowfish(3), Tie::EncryptedHash(3), Convert::ASCII::Armour(3), Math::Pari(3), Class::Loader(3), crypt-rsa-interoperability(3), crypt-rsa-interoperability-table(3).


All bug reports related to Crypt::RSA should go to at

Crypt::RSA is considered to be stable. If you are running into a problem, it’s likely of your own making. Please check your code and consult the documentation before posting a bug report. A google search with the error message might also shed light if it is a common mistake that you’ve made.

If the module installation fails with a Segmentation Fault or Bus Error, it is likely a Math::Pari issue. Please consult Math::Pari bugs on or open a bug there. There have been known issues on HP-UX and SunOS systems (with Math::Pari), so if you are on those OSes, please consult Math::Pari resources before opening a Crypt::RSA bug.


Chronologically sorted (for the most part).
1 <B>R. Rivest, A. Shamir, L. Aldeman.B> A Method for Obtaining Digital Signatures and Public-Key Cryptosystems (1978).
2 <B>U. Maurer.B> Fast Generation of Prime Numbers and Secure Public-Key Cryptographic Parameters (1994).
3 <B>M. Bellare, P. Rogaway.B> Optimal Asymmetric Encryption - How to Encrypt with RSA (1995).
4 <B>M. Bellare, P. Rogaway.B> The Exact Security of Digital Signatures - How to sign with RSA and Rabin (1996).
5 <B>B. Schneier.B> Applied Cryptography, Second Edition (1996).
6 <B>A. Menezes, P. Oorschot, S. Vanstone.B> Handbook of Applied Cryptography (1997).
7 <B>D. Boneh.B> Twenty Years of Attacks on the RSA Cryptosystem (1998).
8 <B>D. Bleichenbacher, M. Joye, J. Quisquater.B> A New and Optimal Chosen-message Attack on RSA-type Cryptosystems (1998).
9 <B>B. Kaliski, J. Staddon.B> Recent Results on PKCS #1: RSA Encryption Standard, RSA Labs Bulletin Number 7 (1998).
10 <B>B. Kaliski, J. Staddon.B> PKCS #1: RSA Cryptography Specifications v2.0, RFC 2437 (1998).
11 <B>SSH Communications Security.B> SSH 1.2.7 source code (1998).
12 <B>S. Simpson.B> PGP DH vs. RSA FAQ v1.5 (1999).
13 <B>RSA Laboratories.B> Draft I, PKCS #1 v2.1: RSA Cryptography Standard (1999).
14 <B>E. Young, T. Hudson, OpenSSL Team.B> OpenSSL 0.9.5a source code (2000).
15 Several Authors. The sci.crypt FAQ at
16 <B>Victor Shoup.B> A Proposal for an ISO Standard for Public Key Encryption (2001).


Hey! <B>The above document had some coding errors, which are explained below:B>
Around line 533: Non-ASCII character seen before =encoding in ’Gene\k:`che’. Assuming ISO8859-1
Around line 582: =over without closing =back
Search for    or go to Top of page |  Section 3 |  Main Index

perl v5.20.3 CRYPT::RSA (3) 2009-06-07

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.