Home » Encryption » Crypt_RSA » Bug #7942
Fatal error: Call to a member function getWrapperName()
Details
| Submitted | 2006-06-20 08:55 UTC |
|---|---|
| From | tof dot news at guerville dot com |
| Status | Bogus |
| Package | Crypt_RSA |
| PHP Version | 5.1.4 |
| OS | Linux RedHat AS4 |
| Roadmaps | (Not assigned) |
Comments
[2006-06-20 08:55 UTC] tof dot news at guerville dot com
Description:
------------
when i try to use Cryp_RSA with a plugin (http://meta.wikimedia.org/wiki/PageProtection) for mediawiki (http://www.mediawiki.org/wiki/MediaWiki) i have this erro and i don't understand:
Fatal error: Call to a member function getWrapperName() on a non-object in /usr/share/pear/Crypt/RSA/KeyPair.php on line 698
I have generated my like this:
openssl genrsa -out private.pem
openssl req -new -x509 -key private.pem -out public.pem -days 365000
My original post from the plugin and without response: http://meta.wikimedia.org/wiki/Talk:PageProtection#getWrapperName_error
Thx
Christophe
Test script:
---------------
<?php
define("RSA_PEM_FILE", "private.pem");
require_once("PEAR.php");
require_once("Crypt/RSA.php");
/**
* Handles encryption.
*/
class Encryption{
var $mKeypair;
/**
* Creates a new file holding PEM-string.
*/
function createPemFile()
{
$keypair = new Crypt_RSA_KeyPair(256);
$str = $keypair->toPEMString();
file_put_contents(RSA_PEM_FILE, $str);
}
/**
* Constructor. Ensures PEM-file exists and reads private
* key from this file.
*/
function Encryption()
{
if (!file_exists(RSA_PEM_FILE)) {
$this->createPemFile();
}
$this->mKeypair = new Crypt_RSA_KeyPair(0);
$this->mKeypair = $this->mKeypair->fromPEMString(
file_get_contents(RSA_PEM_FILE));
}
/**
* Decrypts an RSA-encrypted text.
* @param text Encrypted text
* @return Plaintext
*/
function decrypt($text) {
$rsa = new Crypt_RSA;
$dec = $rsa->decrypt($text, $this->mKeypair->getPrivateKey());
if ($dec == "") {
return $text;
}
return $dec;
}
/**
* Encrypts an text with RSA
* @param text Plaintext
* @return RSA-encrypted text.
*/
function encrypt($text) {
$rsa = new Crypt_RSA;
return $rsa->encrypt($text, $this->mKeypair->getPublicKey());
}
}
?>
[2006-06-21 01:50 UTC] valyala at php dot net
Sorry, but your problem does not imply a bug in PEAR itself. For a
list of more appropriate places to ask for help using PEAR, please
visit http://pear.php.net/support/ as this bug system is not the
appropriate forum for asking support questions.
Thank you for your interest in PEAR.
It is not a bug.
You must check for errors after each Crypt_RSA function call. For instance:
// generate a key
$keypair = new Crypt_RSA_KeyPair(256);
// error check
if ($keypair->isError()) {
echo "error while initializing Crypt_RSA_KeyPair object:\n";
$erorr = $key_pair->getLastError();
echo $error->getMessage(), "\n";
}
It is possible to automate error checks by providing error handler hook when constructing Crypt_RSA objects. For instance:
// error handler
function my_error_handler($obj)
{
if ($obj->isError()) {
$error = $obj->getLastError();
echo "error: ", $error->getMessage(), "\n";
exit;
}
}
// create $keypair object using my_error_handler()
// as error handler
$keypair = new Crypt_RSA_KeyPair(256, 'default', 'my_error_handler');
// now all possible errors at $keypair object
// will be catched by my_error_handler() function
// so, there is no need to check for errors after
// any operation with $keypair.