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: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#### Tags:

author: | Jim Wigginton <terrafrost@php.net>
version: | $Id: RSA.php,v 1.2 2011/05/19 18:02:11 gruberroland Exp $
copyright: | MMIX Jim Wigginton
link: | http://phpseclib.sourceforge.net
license: | MIT License

#### Includes:

require_once('Math/BigInteger.php') [line 75]
Include Math_BigInteger
require_once('Crypt/Random.php') [line 80]
Include Crypt_Random
require_once('Crypt/Hash.php') [line 85]
Include Crypt_Hash

### CRYPT_RSA_ENCRYPTION_OAEP [line 101]

`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 108]

`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 175]

`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_PRIVATE_FORMAT_PUTTY [line 179]

`CRYPT_RSA_PRIVATE_FORMAT_PUTTY = 1`

PuTTY formatted private key

#### Tags:

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

[ Top ]

### CRYPT_RSA_PRIVATE_FORMAT_XML [line 183]

`CRYPT_RSA_PRIVATE_FORMAT_XML = 2`

XML formatted private key

#### Tags:

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

[ Top ]

### CRYPT_RSA_PUBLIC_FORMAT_OPENSSH [line 218]

`CRYPT_RSA_PUBLIC_FORMAT_OPENSSH = 6`

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 208]

`CRYPT_RSA_PUBLIC_FORMAT_PKCS1 = 4`

PKCS#1 formatted public key

#### Tags:

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

[ Top ]

### CRYPT_RSA_PUBLIC_FORMAT_RAW [line 204]

`CRYPT_RSA_PUBLIC_FORMAT_RAW = 3`

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_PUBLIC_FORMAT_XML [line 212]

`CRYPT_RSA_PUBLIC_FORMAT_XML = 5`

XML formatted public key

#### Tags:

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

[ Top ]

### CRYPT_RSA_SIGNATURE_PKCS1 [line 132]

`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 125]

`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 Tue, 22 Nov 2011 16:30:05 +0100 by phpDocumentor 1.4.1