How to create a Crypt :: RSA object from a module, exponent and private exponent?

I am trying to port the following php functions to perl:

public function loadKey($mod, $exp, $type = 'public') { $rsa = new Crypt_RSA(); $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1; $rsa->setHash('sha256'); $rsa->modulus = new Math_BigInteger(Magicsig::base64_url_decode($mod), 256); $rsa->k = strlen($rsa->modulus->toBytes()); $rsa->exponent = new Math_BigInteger(Magicsig::base64_url_decode($exp), 256); // snip... } 

I need to convert a string to a form ("RSA. $ Mod. $ Exp. $ Private_exp"):

 RSA.mVgY8RN6URBTstndvmUUPb4UZTdwvwmddSKE5z_jvKUEK6yk1u3rrC9yN8k6FilGj9K0eeUPe2hf4Pj-5CmHww==.AQAB.Lgy_yL3hsLBngkFdDw1Jy9TmSRMiH6yihYetQ8jy-jZXdsZXd8V5ub3kuBHHk4M39i3TduIkcrjcsiWQb77D8Q== 

... for the Crypt :: RSA object. I have separated the components, so I have $ mod, $ exp and $ private_exp, but the Perl Crypt :: RSA API does not seem to be able to explicitly install.

+6
php perl rsa
source share
1 answer

Worked at IRC, documenting it here for the rest of the world: it is completely undocumented, but Crypt::RSA::Key has methods called n , e and d that correspond to a module, a public exponent, and a private exponent. Modulation errors in the verification function (which should work if p and q not available, but n is, but does not actually do this), it is possible to create a working key with these methods.

We solved the problem together by subclassing Crypt::RSA::Key::Private using the factory method, which decodes base64 encoding (using MIME :: Base64 :: URLSafe ) and additional binary encoding (using Math :: BigInt β†’ from_hex and unpack "H*" ), and then installs these three private elements, and <t29 Modules> could take this as a key.

+5
source share

All Articles