Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Crypt::RSA dies: Can't call method "encryptblock" on an undefined value

by rupesh (Hermit)
on Jul 20, 2005 at 14:38 UTC ( #476510=perlquestion: print w/ replies, xml ) Need Help??
rupesh has asked for the wisdom of the Perl Monks concerning the following question:


OK, a wierd title, but I couldn't think of anything else.
Here's what I did after I installed Crypt::RSA.

Had a look at the author's tutorial at perl's own website.
Followed suit and prepared this code:
#!/usr/bin/perl use strict; use Crypt::RSA; my $message="string"; my $rsa = new Crypt::RSA; my ($public, $private) = $rsa->keygen( Size => 64 ); print "My Public key is: $public ", $public->serialize(); print "My Private key is: $private", $private->serialize(); my $c = $rsa->encrypt( Message => $message, Key => $public, ) or warn +"$!\n"; print "My cipher text is: $c\n"; my $nmessage = $rsa->decrypt( Ciphertext => $c, Key => $private, ); print "My plain text is: $nmessage\n";
Modified the RSA.pm to print certain messages in the enrypt subroutine:
.... ...... .... sub encrypt { my ($self, %params) = @_; my $plaintext = $params{Message} || $params{Plaintext}; my $key = $params{Key}; print "\n$plaintext\n$key\n"; return $self->error ($key->errstr, \%params, $key, \$plaintext) unless $key->check(); print "\nAfter self error\n"; my $blocksize = blocksize ( $$self{es}->encryptblock (Key => $key) +, length($plaintext) ); print "\nAfter block size\n"; return $self->error("Message too long.", \$key, \%params) if $bloc +ksize <= 0; print "\nAfter self error\n"; my $cyphertext; .... ....
Executed the code and got the following message:
My Public key is: Crypt::RSA::Key::Public=HASH(0x8132390) $VAR1 = bles +s( { 'e' => 65537, 'n' => '10270622025769038677', 'Version' => '1.91' }, 'Crypt::RSA::Key::Public' ); My Private key is: Crypt::RSA::Key::Private=HASH(0x8132378)$VAR1 = ble +ss( { 'Version' => '1.91', 'Checked' => 0, 'private' => { '_phi' => '10270622019208864620', '_n' => '10270622025769038677', '_q' => '2581267387', '_p' => '3978906671', '_u' => '564982676', '_dp' => '2208958913', '_dq' => '2285751125', '_d' => '4317024349041710693', '_e' => '65537' }, 'Cipher' => 'Blowfish' }, 'Crypt::RSA::Key::Private' ); string Crypt::RSA::Key::Public=HASH(0x8132390) After self error Can't call method "encryptblock" on an undefined value at /usr/lib/per +l5/site_perl/5.8.0/Crypt/RSA.pm line 98.
Haven't been able to figure out why the "blocksize" method is failing.

Your thoughts?

Thanks,
Rupesh.

Edited by Arunbear: Changed title from 'The "R", the "S" and the "A"...', as per Monastery guidelines

Comment on Crypt::RSA dies: Can't call method "encryptblock" on an undefined value
Select or Download Code
Re: Crypt::RSA dies: Can't call method "encryptblock" on an undefined value
by Anonymous Monk on Jul 20, 2005 at 15:56 UTC
    If you read the error message, you see that the problem isn't with blocksize. The problem is with $$self{es}. You assume $$self{es} exists, and contains an object - but $$self{es} is undefined, it probably doesn't exist.

    From the code given, I cannot deduce what $$self{es} is supposed to be. Or that it even is suposed to exist.

Re: Crypt::RSA dies: Can't call method "encryptblock" on an undefined value
by Anonymous Monk on Jan 14, 2009 at 15:10 UTC
    Your lib path might be messed up somehow. When I got this error, I traced it down to the call to Class::Loader's _load method. For some reason in certain circumstances it quietly fails, leaving a null. Just an FYI, I explicitly set the object reference, and I'm getting provider errors in Crypt::Random. I think your only solution is to get it liking the classpath somehow.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://476510]
Approved by Tanalis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2014-12-28 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls