Your get_pubkey function better be returning a Crypt::RSA::Key::Public object. That's a public key object in the Crypt::RSA world.

Because that's the thing you're passing to Crypt::RSA, and that's what it expects. $public_key, in other words, should be an object of type Crypt::RSA::Key::Public. That's why you're getting the "Can't call method n" on $public_key error: because you're probably giving it a string or something, and the string obviously can't support method calls.

So what you should be doing is having your get_pubkey return a Crypt::RSA::Key::Public object. How do you do that? Well, you create such an object, then fill it with values. An RSA public key should have two components: n, the RSA modulus; and e, the exponent. This is used when doing public-key encryption on a message. So, in get_pubkey, you can create a public key object:

my $key = Crypt::RSA::Key::Public->new;
and then fill it the values, which you're apparently getting from *somewhere* (your base64-decoded string?):
$key->n($n); $key->e($e);
Perhaps, in your case, $n and $e are in your @fields array. I don't know, because that's specific to your code.

Then return $key from your function.

Take a look at the source of Crypt::RSA::Key for another example. The generate method generates a set of public and private keys from scratch (finding primes, deriving key attributes, etc.).


In reply to Re: Crypt fun by btrott
in thread Crypt fun by tame1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.