note 104418 deleted from function.openssl-pkey-get-public by danbrown
| From: | danbrown@php.net | Date: | Tue, 14 Jun 2011 19:11:49 +0000 |
| Subject: | note 104418 deleted from function.openssl-pkey-get-public by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180527@lists.php.net to get a copy of this message | ||
Note Submitter: ppostma1
----
OK, this took a while to figure out.
Most places put out their keys in separate Modulus/Exponent formats. This won't work, and they
do not directly apply to make a format that openssl_pkey_get_public accepts.
RSAKeyValue
Modulus: 2Tkc9yx6dBIk ... /Modulus
Exponent AQAB /Exponent
/RSAKeyValue
They have to be converted to the full public signature. I used http://phpseclib.sourceforge.net/ and the calls:
$modulus = '2Tkc9yx6...';
$mbin = base64_decode($modulus);
$mhex = bin2hex($mbin);
$exponent = 'AQAB';
$ebin = base64_decode($exponent);
$ehex = bin2hex($ebin);
$rsa->_convertPublicKey(new Math_BigInteger($mhex, 16), new Math_BigInteger($ehex, 16));
Math_BigInteger coming from the modseclib package
like info at steyla pointed out, its PKCS, which need to have
'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' prepended, and then re-wrapped to make it an X509
signature:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2Tkc9yx6dBIk+pTgyyaX91b+NY0DK7nO
MLZpZCV6/zzn8js2AujMOaLs5uXc5pGaBWu1eJbSPTIm...
NKYTtwIDAQAB
-----END PUBLIC KEY-----
That prefix only works on the 2048 bit keys. Or, you can just fully use phpseclib for more more
robust options and functionality as wall as formats, etc.