Why delete publicExponent from PUBLIC_RAW key?

Get help with using the PHP Secure Communications Library.

Moderator: Nuxius

Forum rules
The purpose of this forum is to provide support for phpseclib, a pure PHP SSH / SFTP / RSA library.

Posts by new users are held in a moderation queue and are not publicly visible until the post is approved.

Why delete publicExponent from PUBLIC_RAW key?

Postby spacewrench » Sat Jun 02, 2012 10:30 pm

I have an RSA modulus and public-key exponent stored in a database as hex strings. I've managed to get them into a phpseclib RSA key:

Code: Select all
$rsa = new Crypt_RSA( );
$rsa->loadKey( array( 'n' => new Math_BigInteger( 'modulus hex string', 16 ),
                                'e' => new Math_BigInteger( 'pub exponent', 16 ) ),
                       CRYPT_RSA_PUBLIC_FORMAT_RAW );


and I can encrypt using the key. However, I'd also like to be able to print out the public key in PKCS1 format, but when I try, getPublicKey() returns false. After investigating, it appears that loadKey moves ['publicExponent'] to ['exponent'] and sets ['publicExponent'] to false (RSA.php:1193).

Why is that?
spacewrench
Traveler
 
Posts: 1
Joined: Sat Jun 02, 2012 9:44 pm

Re: Why delete publicExponent from PUBLIC_RAW key?

Postby TerraFrost » Wed Jun 06, 2012 5:12 am

Some private keys can be indistinguishable from public keys. In those cases calling getPublicKey() doesn't make a lot of sense.

As of the 0.2.2 release getPublicKey() can only be called when the key is clearly a private key and has a corresponding public key.

As of the latest github.com version even regular public keys can be treated as public keys if you do $rsa->setPublicKey() first.

As for why publicExponent is unset... the above is why. Because some private keys can be indistinguishable for regular keys.
TerraFrost
Legendary Guard
 
Posts: 12217
Joined: Wed Dec 04, 2002 6:37 am


Return to phpseclib support

Who is online

Users browsing this forum: No registered users and 2 guests