I would like to know how could I sign a file in php. I need to sign an XML file. When I'm executing this piece of code, it gives me the following error:
Warning: openssl_sign(): supplied key param cannot be coerced into a private key in C:\xampp\htdocs\test\index.php on line 35
Warning: openssl_free_key() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test\index.php on line 38
The code is this one:
$data->save("test.xml");
$signature;
$pkeyid = openssl_pkey_get_public("./public.cer");
$path = 'test.xml';
openssl_sign($path, $signature, $pkeyid);
openssl_free_key($pkeyid);
Fixed: Ok, so I had a misconception about the fact that I should sign data with a public certificate, and also I didn't load the data properly. I changed it and It worked :) The function that I've used is this one:
$pkeyid = openssl_pkey_get_private(file_get_contents('./private.key'));