Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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 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/ line 98.
Haven't been able to figure out why the "blocksize" method is failing.

Your thoughts?


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

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://476510]
Approved by Tanalis
[Eily]: can't the nodelet be moved though? Maybe you could put one that doesn't change first ("Sections" or "Find Nodes" for example)
[Eily]: "Other Users" seems like a poor choice :P
[Eily]: nope, Nodelet Settings doesn't let you move the XP Nodelet, CSS might
[marinersk]: That would mitigate the distraction/jangle issue, but then the information wouldn't be easy to find when it is populated. Plus, I don't currently see a way to move it, but I'm not done poking around on that point yet.
[marinersk]: Ah, you beat me to it.

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2017-05-29 14:09 GMT
Find Nodes?
    Voting Booth?