note 104418 added to function.openssl-pkey-get-public

From: Date: Tue, 14 Jun 2011 18:56:58 +0000
Subject: note 104418 added to function.openssl-pkey-get-public
Groups: php.notes 
Request: Send a blank email to php-notes+get-180524@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 216.82.251.229 ---- Manual Page -- http://www.php.net/manual/en/function.openssl-pkey-get-public.php Edit -- https://master.php.net/note/edit/104418 Del: integrated -- https://master.php.net/note/delete/104418/integrated Del: useless -- https://master.php.net/note/delete/104418/useless Del: bad code -- https://master.php.net/note/delete/104418/bad+code Del: spam -- https://master.php.net/note/delete/104418/spam Del: non-english -- https://master.php.net/note/delete/104418/non-english Del: in docs -- https://master.php.net/note/delete/104418/in+docs Del: other reasons-- https://master.php.net/note/delete/104418 Reject -- https://master.php.net/note/reject/104418 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180524) next »