The openssl extension is enabled in php.ini and php_openssl.dll is present in xampp\php\ext\.
In the course of writing and testing a function to decrypt data using openssl_pkey_get_private I receive the following:
Warning: openssl_private_decrypt() [function.openssl-private-decrypt]: key parameter is not a valid private key in ...<line number in source code>
After much hair pulling as to the error, I ran a simple test:
- Code: Select all
<?php
$passphrase="<has value in source>";
$priv_key_file_name = ("private.pem");
if (openssl_pkey_get_private(array("file://$priv_key_file_name", $passphrase)))
{
print "\nPrivate Key OK\n\n";
} else {
print "\nPrivate key NOT OK\n\n";
}
?>
The test failed on my local machine for development but succeeded on the actual server I intend to publish this application to. Next, I tried running my application on the same host server. It works perfectly. Something is wrong with PHP on my XAMPP installation. It is odd for I can encrypt without a problem.
Here is my function
- Code: Select all
$priv_key_file_name = ("private.pem");
$phrase = "<has value in source>";
function decrypt ($encrypted, $priv_key_file_name, $phrase) {
$private_key = openssl_pkey_get_private(array("file://$priv_key_file_name", $phrase));
$encryptedData = base64_decode($encrypted);
$data = '';
openssl_private_decrypt($encryptedData, $data, $private_key);
return $data;
}
In debugging, $private_key comes up empty on an echo and FALSE in my IDE with Xdebug.
There is still a lot to do on this and it would be better if I can continue my development under XAMPP rather than uploading to and testing on the production server.
Any ideas?