1

I am quite new to php and public private key..

Can somebody guide me .. how to generate public private key in php and store hem in variables.

Thanks

Update my code lloks like this.

   $privateKey = openssl_pkey_new(array('private_key_bits' => 2048));
   $details = openssl_pkey_get_public($privateKey);
   $publicKey = $details['key'];

   echo $publicKey;
Manpreet Oberoi
  • 385
  • 3
  • 4
  • 13
  • 2
    Possible duplicate of [Can PHP OpenSSL generate private/public key/certificate pairs?](http://stackoverflow.com/questions/7414044/can-php-openssl-generate-private-public-key-certificate-pairs) – Charlotte Dunois Sep 12 '16 at 09:41

1 Answers1

1

You can use openssl_pkey_new() of php to generate private key which is documented in detail here For public key get the details using $all_values = openssl_pkey_get_details($privateKey); function and get public key out of it like $all_values['key'];

Update:

or there is also another post on stackoverflow stating the same thing:here

Community
  • 1
  • 1
MKB
  • 777
  • 1
  • 9
  • 27
  • i am getting this error " openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in " – Manpreet Oberoi Sep 12 '16 at 09:36
  • Can you please paste the code you are using to generate the key. As stated in the error you must be using a boolean type of parameter to pass to the function which should be resource – MKB Sep 12 '16 at 09:40