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

Class: Crypt_RSA_Key

Source Location: /Crypt_RSA-1.2.1/RSA/Key.php

Class Overview

Crypt_RSA_ErrorHandler
   |
   --Crypt_RSA_Key

Crypt_RSA_Key class, derived from Crypt_RSA_ErrorHandler


Author(s):

Version:

  • Release: @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 95]
Crypt_RSA_Key class, derived from Crypt_RSA_ErrorHandler

Provides the following functions:

  • getKeyLength() - returns bit key length
  • getExponent() - returns key exponent as binary string
  • getModulus() - returns key modulus as binary string
  • getKeyType() - returns type of the key (public or private)
  • toString() - returns serialized key as string
  • fromString($key_str) - static function; returns key, unserialized from string
  • isValid($key) - static function for validating of $key
Example usage: // create new 1024-bit key pair $key_pair = new Crypt_RSA_KeyPair(1024);

// get public key (its class is Crypt_RSA_Key) $key = $key_pair->getPublicKey();

// get key length $len = $key->getKeyLength();

// get modulus as string $modulus = $key->getModulus();

// get exponent as string $exponent = $key->getExponent();

// get string represenation of key (use it instead of serialization of Crypt_RSA_Key object) $key_in_str = $key->toString();

// restore key object from string using 'BigInt' math wrapper $key = Crypt_RSA_Key::fromString($key_in_str, 'BigInt');

// error check if ($key->isError()) { echo "error while unserializing key object:\n"; $erorr = $key->getLastError(); echo $error->getMessage(), "\n"; }

// validate key if (Crypt_RSA_Key::isValid($key)) echo 'valid key'; else echo 'invalid key';

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



[ Top ]


Method Detail

Crypt_RSA_Key (Constructor)   [line 154]

Crypt_RSA_Key Crypt_RSA_Key( string $modulus, string $exp, string $key_type, [string $wrapper_name = 'default'], [string $error_handler = ''])

Crypt_RSA_Key constructor.

You should pass in the 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.

  • Access: public

Parameters:

string   $modulus   —  key modulus
string   $exp   —  key exponent
string   $key_type   —  type of the key (public or private)
string   $wrapper_name   —  wrapper to use
string   $error_handler   —  name of error handler function

[ Top ]

factory   [line 200]

object new factory( string $modulus, string $exp, string $key_type, [string $wrapper_name = 'default'], [string $error_handler = ''])

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

Parameters:

string   $modulus   —  key modulus
string   $exp   —  key exponent
string   $key_type   —  type of the key (public or private)
string   $wrapper_name   —  wrapper to use
string   $error_handler   —  name of error handler function

[ Top ]

fromString   [line 289]

object key fromString( string $key_str, [string $wrapper_name = 'default'])

Returns Crypt_RSA_Key object, unserialized from string representation of key.

optional parameter $wrapper_name - is the name of math wrapper, which will be used during unserialization of this object.

This function can be called statically: $key = Crypt_RSA_Key::fromString($key_in_string, 'BigInt');

  • Return: as Crypt_RSA_Key object
  • Access: public

Parameters:

string   $key_str   —  RSA key, serialized into string
string   $wrapper_name   —  optional math wrapper name

[ Top ]

getExponent   [line 241]

string getExponent( )

Returns exponent part of the key as binary string, which can be used to construct new Crypt_RSA_Key object.
  • Return: exponent as binary string
  • Access: public

[ Top ]

getKeyLength   [line 217]

int getKeyLength( )

Calculates bit length of the key
  • Return: bit length of key
  • Access: public

[ Top ]

getKeyType   [line 252]

string getKeyType( )

Returns key type (public, private)
  • Return: key type (public, private)
  • Access: public

[ Top ]

getModulus   [line 229]

string getModulus( )

Returns modulus part of the key as binary string, which can be used to construct new Crypt_RSA_Key object.
  • Return: modulus as binary string
  • Access: public

[ Top ]

isValid   [line 308]

bool isValid( object $key)

Validates key This function can be called statically: $is_valid = Crypt_RSA_Key::isValid($key)

Returns true, if $key is valid Crypt_RSA key, else returns false

  • Return: true if $key is valid, else false
  • Access: public

Parameters:

object   $key   —  Crypt_RSA_Key object for validating

[ Top ]

toString   [line 263]

string toString( )

Returns string representation of key
  • Return: key, serialized to string
  • Access: public

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:28:16 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.