I wants to write the functionality to create a signature using the algorithem of SHA256withRSA, I have tried but nothing is printing.Can anyone please update my code.
I have tried but I am not able to identify my mistake.
Thnaks in advance!!
My PHP code
<?php
$data = "Sample Text";
$private_key = <<<EOD
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBANDiE2+Xi/WnO+s120NiiJhNyIButVu6zxqlVzz0wy2j4kQVUC4Z
RZD80IY+4wIiX2YxKBZKGnd2TtPkcJ/ljkUCAwEAAQJAL151ZeMKHEU2c1qdRKS9
sTxCcc2pVwoAGVzRccNX16tfmCf8FjxuM3WmLdsPxYoHrwb1LFNxiNk1MXrxjH3R
6QIhAPB7edmcjH4bhMaJBztcbNE1VRCEi/bisAwiPPMq9/2nAiEA3lyc5+f6DEIJ
h1y6BWkdVULDSM+jpi1XiV/DevxuijMCIQCAEPGqHsF+4v7Jj+3HAgh9PU6otj2n
Y79nJtCYmvhoHwIgNDePaS4inApN7omp7WdXyhPZhBmulnGDYvEoGJN66d0CIHra
I2SvDkQ5CmrzkW5qPaE2oO7BSqAhRZxiYpZFb5CI
-----END RSA PRIVATE KEY-----
EOD;
$binary_signature = "";
$algo = "SHA256WithRSA";
openssl_sign($data, $binary_signature, $private_key, $algo);
$signature = base64_encode($binary_signature);
echo $timestamp = time();// I need here PHP curent date and timestamp
echo "<br>";
print_r($signature);
?>
UPDATED PHP CODE
<?php
$data = "Sample Text";
$private_key = <<<EOD
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBANDiE2+Xi/WnO+s120NiiJhNyIButVu6zxqlVzz0wy2j4kQVUC4Z
RZD80IY+4wIiX2YxKBZKGnd2TtPkcJ/ljkUCAwEAAQJAL151ZeMKHEU2c1qdRKS9
sTxCcc2pVwoAGVzRccNX16tfmCf8FjxuM3WmLdsPxYoHrwb1LFNxiNk1MXrxjH3R
6QIhAPB7edmcjH4bhMaJBztcbNE1VRCEi/bisAwiPPMq9/2nAiEA3lyc5+f6DEIJ
h1y6BWkdVULDSM+jpi1XiV/DevxuijMCIQCAEPGqHsF+4v7Jj+3HAgh9PU6otj2n
Y79nJtCYmvhoHwIgNDePaS4inApN7omp7WdXyhPZhBmulnGDYvEoGJN66d0CIHra
I2SvDkQ5CmrzkW5qPaE2oO7BSqAhRZxiYpZFb5CI
-----END RSA PRIVATE KEY-----
EOD;
$binary_signature = "";
$algo = OPENSSL_ALGO_SHA256;
openssl_sign($data, $binary_signature, $private_key, $algo);
$signature = base64_encode($binary_signature);
//verify signature
$r = openssl_verify($data, $signature, $public_key_pem, "sha256WithRSAEncryption");
var_dump($r);
?>
OPENSSL_ALGO_SHA256and you'll get the signature"xEjyq+pwgRLpc+ikNT8HQRiE+vYtHjwaBafhaqW1ueu8ftxvg1PDtPZ1jQGjwvtuixk+yg90nbpjF0nUBshqNA=="OPENSSL_ALGO_SHA256getting error ( ! ) Warning: openssl_sign(): Unknown signature algorithm. in C:\xampp\htdocs\test\index.php on line 20