Crypt_RSA
[ class tree: Crypt_RSA ] [ index: Crypt_RSA ] [ all elements ]

Class: Crypt_RSA

Source Location: /Crypt_RSA-1.0.0/RSA.php

Class Overview

Crypt_RSA_ErrorHandler
   |
   --Crypt_RSA

Crypt_RSA class, derived from Crypt_RSA_ErrorHandler


Author(s):

Version:

  • @package_version@

Copyright:

  • 2005 Alexander Valyalkin

Methods


Inherited Variables

Inherited Methods

Class: Crypt_RSA_ErrorHandler

Crypt_RSA_ErrorHandler::getErrorHandler()
returns name of current error handler, or null if there is no error handler
Crypt_RSA_ErrorHandler::getErrorList()
Returns list of all errors, pushed to error list by $this->pushError()
Crypt_RSA_ErrorHandler::getLastError()
Returns last error from errors list or false, if list is empty
Crypt_RSA_ErrorHandler::isError()
Returns true if list of errors is not empty, else returns false
Crypt_RSA_ErrorHandler::pushError()
pushes error object $error to the error list
Crypt_RSA_ErrorHandler::setErrorHandler()
sets error handler to function with name $func_name.

Class Details

[line 119]
Crypt_RSA class, derived from Crypt_RSA_ErrorHandler

Provides the following functions:

  • setParams($params) - sets parameters of current object
  • encrypt($plain_data, $key = null) - encrypts data
  • decrypt($enc_data, $key = null) - decrypts data
  • createSign($doc, $private_key = null) - signs document by private key
  • validateSign($doc, $signature, $public_key = null) - validates signature of document
Example usage: // creating an error handler $error_handler = create_function('$obj', 'echo "error: ", $obj->getMessage(), "\n"');

// 1024-bit key pair generation $key_pair = new Crypt_RSA_KeyPair(1024);

// check consistence of Crypt_RSA_KeyPair object $error_handler($rsa_obj);

// creating Crypt_RSA object $rsa_obj = new Crypt_RSA;

// check consistence of Crypt_RSA object $error_handler($rsa_obj);

// set error handler on Crypt_RSA object ( see Crypt/RSA/ErrorHandler.php for details ) $rsa_obj->setErrorHandler($error_handler);

// encryption (usually using public key) $enc_data = $rsa_obj->encrypt($plain_data, $key_pair->getPublicKey());

// decryption (usually using private key) $plain_data = $rsa_obj->decrypt($enc_data, $key_pair->getPrivateKey());

// signing $signature = $rsa_obj->createSign($document, $key_pair->getPrivateKey());

// signature checking $is_valid = $rsa_obj->validateSign($document, $signature, $key_pair->getPublicKey());

// signing many documents by one private key $rsa_obj = new Crypt_RSA(array('private_key' => $key_pair->getPrivateKey())); // check consistence of Crypt_RSA object $error_handler($rsa_obj); // set error handler ( see Crypt/RSA/ErrorHandler.php for details ) $rsa_obj->setErrorHandler($error_handler); // sign many documents $sign_1 = $rsa_obj->sign($doc_1); $sign_2 = $rsa_obj->sign($doc_2); //... $sign_n = $rsa_obj->sign($doc_n);

// changing default hash function, which is used for sign // creating/validation $rsa_obj->setParams(array('hash_func' => 'md5'));

// using factory() method instead of constructor (it returns PEAR_Error object on failure) $rsa_obj = &Crypt_RSA::factory(); if (PEAR::isError($rsa_obj)) { echo "error: ", $rsa_obj->getMessage(), "\n"; }



[ Top ]


Method Detail

Crypt_RSA (Constructor)   [line 190]

Crypt_RSA Crypt_RSA( [array $params = null], [string $wrapper_name = 'default'], [string $error_handler = ''])

Crypt_RSA constructor.
  • Access: public

Parameters:

array   $params   —  Optional associative array of parameters, such as: enc_key, dec_key, private_key, public_key, hash_func. See setParams() method for more detailed description of these parameters.
string   $wrapper_name   —  Name of math wrapper, which will be used to perform different operations with big integers. See contents of Crypt/RSA/Math folder for examples of wrappers. Read docs/Crypt_RSA/docs/math_wrappers.txt for details.
string   $error_handler   —  name of error handler function

[ Top ]

createSign   [line 463]

mixed createSign( string $document, [object $private_key = null], [string $hash_func = null])

Creates sign for document $document, using $this->_private_key or $private_key as private key and $this->_hash_func or $hash_func as hash function.
  • Return: signature of $document as string on success or false on error
  • Access: public

Parameters:

string   $document   —  document, which must be signed
object   $private_key   —  private key (object of Crypt_RSA_Key type)
string   $hash_func   —  name of hash function, which will be used during signing

[ Top ]

decrypt   [line 396]

mixed decrypt( string $enc_data, [object $key = null])

Decrypts $enc_data by the key $this->_dec_key or $key.
  • Return: decrypted data as string on success or false on error
  • Access: public

Parameters:

string   $enc_data   —  encrypted data as string
object   $key   —  decryption key (object of RSA_Crypt_Key class)

[ Top ]

decryptBinary   [line 412]

mixed decryptBinary( string $enc_data, [object $key = null])

Decrypts $enc_data by the key $this->_dec_key or $key.
  • Return: decrypted data as string on success or false on error
  • Access: public

Parameters:

string   $enc_data   —  encrypted data as binary string
object   $key   —  decryption key (object of RSA_Crypt_Key class)

[ Top ]

encrypt   [line 330]

mixed encrypt( string $plain_data, [object $key = null])

Ecnrypts $plain_data by the key $this->_enc_key or $key.
  • Return: encrypted data as string on success or false on error
  • Access: public

Parameters:

string   $plain_data   —  data, which must be encrypted
object   $key   —  encryption key (object of Crypt_RSA_Key class)

[ Top ]

encryptBinary   [line 350]

mixed encryptBinary( string $plain_data, [object $key = null])

Ecnrypts $plain_data by the key $this->_enc_key or $key.
  • Return: encrypted data as binary string on success or false on error
  • Access: public

Parameters:

string   $plain_data   —  data, which must be encrypted
object   $key   —  encryption key (object of Crypt_RSA_Key class)

[ Top ]

factory   [line 230]

object new &factory( [array $params = null], [string $wrapper_name = 'default'])

Crypt_RSA factory.
  • Return: Crypt_RSA object on success or PEAR_Error object on failure
  • Access: public

Parameters:

array   $params   —  Optional associative array of parameters, such as: enc_key, dec_key, private_key, public_key, hash_func. See setParams() method for more detailed description of these parameters.
string   $wrapper_name   —  Name of math wrapper, which will be used to perform different operations with big integers. See contents of Crypt/RSA/Math folder for examples of wrappers. Read docs/Crypt_RSA/docs/math_wrappers.txt for details.

[ Top ]

setParams   [line 255]

bool setParams( array $params)

Accepts any combination of available parameters as associative array:

enc_key - encryption key for encrypt() method dec_key - decryption key for decrypt() method public_key - key for validateSign() method private_key - key for createSign() method hash_func - name of hash function, which will be used to create and validate sign

  • Return: true on success or false on error
  • Access: public

Parameters:

array   $params   —  associative array of permitted parameters (see above)

[ Top ]

validateSign   [line 507]

mixed validateSign( string $document, string $signature, [object $public_key = null], [string $hash_func = null])

Validates $signature for document $document with public key $this->_public_key or $public_key and hash function $this->_hash_func or $hash_func.
  • Return: true, if signature of document is valid false, if signature of document is invalid null on error
  • Access: public

Parameters:

string   $document   —  document, signature of which must be validated
string   $signature   —  signature, which must be validated
object   $public_key   —  public key (object of Crypt_RSA_Key class)
string   $hash_func   —  hash function, which will be used during validating signature

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:20:36 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.