0

I make some code to generate public and private code. It was working ok on one machine, but on other server it is causing "Internal Server Error".

private function keyGen()   
{
    if(is_file($this::pubK_path) )
        exec("rm ".$this::pubK_path);
    if(is_file($this::privK_path) )
        exec("rm ".$this::privK_path);

    $config = array(
        "digest_alg" => "sha512",
        "private_key_bits" => 512,
        "private_key_type" => OPENSSL_KEYTYPE_RSA
    );

    // Create the private and public key
    $this->key = openssl_pkey_new($config);

    $pubkey=openssl_pkey_get_details($this->key);
    $this->pubkey=$pubkey["key"];

    $privK=null;
    openssl_pkey_export($this->key, $privK,$this->pass);
    file_put_contents($this::privK_path, $privK);
    file_put_contents($this::pubK_path, $this->pubkey);
}

Sadly I didn't find any information about this error in any log. I only find that it is caused by this line:

$pubkey=openssl_pkey_get_details($this->key);

Key is generated properly - when I deleted openssl_pkey_get_details, private key was saved in file.

Any ideas what is wrong, or other method to get public key?

jww
  • 97,681
  • 90
  • 411
  • 885

1 Answers1

0

Sadly I didn't find any information about this error in any log.

You can use openssl_error_string() to find out what is openssl_pkey_new() returning, you should see a false or any other OpenSSL error (from here). Like:

<?php
// lets assume you just called an openssl function that failed
while ($msg = openssl_error_string())
    echo $msg . "<br />\n";
?>

Then it should be easy to find the problem (you can update this thread with the error).

Hope it helps!

Community
  • 1
  • 1
JP. Aulet
  • 4,375
  • 4
  • 26
  • 39