Crypt_RSA

# Procedural File: RSA.php

Source Location: /lib/3rdParty/phpseclib/Crypt/RSA.php

## Classes:

Crypt_RSA
  Pure-PHP PKCS#1 compliant implementation of RSA.

## Page Details:

Pure-PHP PKCS#1 (v2.1) compliant implementation of RSA.

PHP versions 4 and 5

Here's an example of how to encrypt and decrypt text with this library:

1. <?php
2. include('Crypt/RSA.php');
4. $rsa = new Crypt_RSA ();
5. extract ($rsa->createKey());
7. $plaintext = 'terrafrost';
9. $rsa->loadKey($privatekey);
10. $ciphertext = $rsa->encrypt($plaintext);
12. $rsa->loadKey($publickey);
13. echo $rsa->decrypt($ciphertext);
14. ?>

Here's an example of how to create signatures and verify signatures with this library:

1. <?php
2. include('Crypt/RSA.php');
4. $rsa = new Crypt_RSA ();
5. extract ($rsa->createKey());
7. $plaintext = 'terrafrost';
9. $rsa->loadKey($privatekey);
10. $signature = $rsa->sign($plaintext);
12. $rsa->loadKey($publickey);
13. echo $rsa->verify($plaintext, $signature) ? 'verified' : 'unverified';
14. ?>

LICENSE: This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

#### Tags:

author: | Jim Wigginton <terrafrost@php.net>
version: | $Id: RSA.php,v 1.1 2010/05/14 14:06:16 gruberroland Exp $
copyright: | MMIX Jim Wigginton
link: | http://phpseclib.sourceforge.net
license: | http://www.gnu.org/licenses/lgpl.txt

#### Includes:

require_once('Crypt/Random.php') [line 77]
Include Crypt_Random
require_once('Crypt/Hash.php') [line 82]
Include Crypt_Hash
require_once('Math/BigInteger.php') [line 72]
Include Math_BigInteger

### CRYPT_RSA_ENCRYPTION_OAEP [line 98]

`CRYPT_RSA_ENCRYPTION_OAEP = 1`

Use Optimal Asymmetric Encryption Padding (OAEP) for encryption / decryption.

Uses sha1 by default.

#### Tags:

see: | Crypt_RSA::setMGFHash()
see: | Crypt_RSA::decrypt()
see: | Crypt_RSA::setHash()
see: | Crypt_RSA::encrypt()
access: | public

[ Top ]

### CRYPT_RSA_ENCRYPTION_PKCS1 [line 105]

`CRYPT_RSA_ENCRYPTION_PKCS1 = 2`

Use PKCS#1 padding.

Although CRYPT_RSA_ENCRYPTION_OAEP offers more security, including PKCS#1 padding is necessary for purposes of backwards compatability with protocols (like SSH-1) written before OAEP's introduction.

#### Tags:

see: | Crypt_RSA::decrypt()
see: | Crypt_RSA::encrypt()
access: | public

[ Top ]

### CRYPT_RSA_PRIVATE_FORMAT_PKCS1 [line 172]

`CRYPT_RSA_PRIVATE_FORMAT_PKCS1 = 0`

PKCS#1 formatted private key

Used by OpenSSH

#### Tags:

see: | Crypt_RSA::setPrivateKeyFormat()
see: | Crypt_RSA::createKey()
access: | public

[ Top ]

### CRYPT_RSA_PUBLIC_FORMAT_OPENSSH [line 203]

`CRYPT_RSA_PUBLIC_FORMAT_OPENSSH = 3`

OpenSSH formatted public key

Place in $HOME/.ssh/authorized_keys

#### Tags:

see: | Crypt_RSA::setPublicKeyFormat()
see: | Crypt_RSA::createKey()
access: | public

[ Top ]

### CRYPT_RSA_PUBLIC_FORMAT_PKCS1 [line 197]

`CRYPT_RSA_PUBLIC_FORMAT_PKCS1 = 2`

PKCS#1 formatted public key

#### Tags:

see: | Crypt_RSA::setPublicKeyFormat()
see: | Crypt_RSA::createKey()
access: | public

[ Top ]

### CRYPT_RSA_PUBLIC_FORMAT_RAW [line 193]

`CRYPT_RSA_PUBLIC_FORMAT_RAW = 1`

Raw public key

An array containing two Math_BigInteger objects.

The exponent can be indexed with any of the following:

0, e, exponent, publicExponent

The modulus can be indexed with any of the following:

1, n, modulo, modulus

#### Tags:

see: | Crypt_RSA::setPublicKeyFormat()
see: | Crypt_RSA::createKey()
access: | public

[ Top ]

### CRYPT_RSA_SIGNATURE_PKCS1 [line 129]

`CRYPT_RSA_SIGNATURE_PKCS1 = 2`

Use the PKCS#1 scheme by default.

Although CRYPT_RSA_SIGNATURE_PSS offers more security, including PKCS#1 signing is necessary for purposes of backwards compatability with protocols (like SSH-2) written before PSS's introduction.

#### Tags:

see: | Crypt_RSA::sign()
see: | Crypt_RSA::verify()
see: | Crypt_RSA::setHash()
access: | public

[ Top ]

### CRYPT_RSA_SIGNATURE_PSS [line 122]

`CRYPT_RSA_SIGNATURE_PSS = 1`

Use the Probabilistic Signature Scheme for signing

Uses sha1 by default.

#### Tags:

see: | Crypt_RSA::setMGFHash()
see: | Crypt_RSA::setSaltLength()
see: | Crypt_RSA::sign()
see: | Crypt_RSA::setHash()
see: | Crypt_RSA::verify()
access: | public

[ Top ]

Documentation generated on Thu, 28 Oct 2010 21:00:31 +0200 by phpDocumentor 1.4.1