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