0

I tried this following code

// Create the keypair
$res=openssl_pkey_new();

// Get private key
openssl_pkey_export($res, $privatekey);

// Get public key
$publickey=openssl_pkey_get_details($res);
$publickey=$publickey["key"];

but i get this error

Warning: openssl_pkey_export(): cannot get key from parameter 1 in ... Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in ...

I already uncomment extension=php_openssl.dll my php.ini file. and openssl supported when i checked in phpinfo(). short of confused. i don't know how to fix this problem.

3 Answers3

0

Check what message the following produces.

var_dump(openssl_error_string());

http://www.php.net/manual/en/function.openssl-error-string.php

William Byrne
  • 506
  • 2
  • 4
  • thankyou for your answer and this is the result string(51) "error:02001003:system library:fopen:No such process" – user2467703 Jun 18 '13 at 05:06
0

$res is supposed to be a resource. This is the return of openssl_pkey_new(). See the Documentation. But it can also be FALSE.

Errors like the one you are seeing often mean that the function that creates the resource, here openssl_pkey_new(), failed. As the documentation says,

Returns a resource identifier for the pkey on success, or FALSE on error.

So you need to check the error. I am not familiar, but openssl_error_string looks promising.

EDIT In Responce: SO question openssl-not-working-on-windows. This appears to be your problem. The processes can not find your openSSL config file. Read this OpenSLL Configuration guide by PHP

Suggestion, Use a while loop to read all the error messages, as described in the link. If it is the same error follow the instructions.

Community
  • 1
  • 1
SH-
  • 1,642
  • 10
  • 13
0

I think you might have better luck with phpseclib, a pure PHP RSA implementation tbh. eg.

<?php
include('Crypt/RSA.php');

$rsa = new Crypt_RSA();

extract($rsa->createKey());

echo "$publickey<br />$privatekey";
?>

That creates a 1024-bit key by default. If you need to customize it above and beyond the default settings lmk.

neubert
  • 15,947
  • 24
  • 120
  • 212