Internal Server error with openssl_sign function

General discussion on PHP
Post Reply
john6582
Posts: 8
Joined: Tue Jul 23, 2013 3:05 pm

Internal Server error with openssl_sign function

Post by john6582 » Tue Oct 06, 2015 10:43 pm

I'm trying to write a simple script that will sign data for me based on the private key. When I run this command with a bogus algorithm it gives me a legit error so I know the function is there. But when I use the default or any other algorithm like SHA256 I get an internal server error. I've looked in PHP.LOG, error and access logs. No clues. Anyone have ideas?

<?php

if ($_POST && $_POST['dataToSign'] and $_POST['privateKey']) {
$hereIsYourSignedData = signData($_POST['dataToSign'], $_POST['privateKey']);
}

?>

<form method="POST">
<p><textarea name="dataToSign" rows="10" cols="200">Enter data to sign here</textarea></p>

<p><textarea name="privateKey" rows="10" cols="200">Enter private key to use here</textarea></p>

<p><input type="submit" name="submit" value="Submit"></p>

</form>

<?php if (isset($hereIsYourSignedData)) { ?>
<p>Here is your signed Data: <?php echo $hereIsYourSignedData; ?></p>
<?php

}

function signData($dataToSign, $privateKey) {

$pkeyid = openssl_pkey_get_private($privateKey);
if($pkeyid) {
$success = openssl_sign($dataToSign, $dataSignature, $pkeyid, "SHA256");

openssl_free_key($pkeyid);

if ($success) {
return $dataSignature;
} else {
echo "<p>Signing failed.</p>";
die();
}
} else {
echo "<p>Unable to get private key ID for Private Key provided.</p>";
die();
}

}

?>

Post Reply