0

I am trying to verify signed data response using php openssl.

I am using php openssl verify method but i cant get it to verify even though the signed data is valid

I tried the following

<?php
$data='BE10000202|20240226154030|405700076188|20240226155800|06||AC|561708940418|BNBL||90.0|BTN';

$signed='4732D17334BE2DECC4136C2FAF4E9A43778EBA277D41E4B32E668B91D3C99B73014914E0FDB045D135B924E56D18F812C504089DE2A1CF4FDB8754A9E2B8517566180CAE16E946AF40E3B4C5AFD4130B2E6E5FC536F353219FD231259C69C2494502A0E4566CE410F28205A636A06C49BA2DA8409A0969F57494E28E25127789016C781A7433B1F51F4FC4BF3DBBF5971AB5A1431E8046E1FCE72D110E442FFEE536F751A358E15FB4DFC183EBF4618BC791B46DE2DCC63132F7E314FBD8A4D2AC6058E7BF4395EDA9762585CCC4113BA6D450F0F82E4B826E38A8AA85D3033931EADFC2E8AE96C66E63F78A5E2AE500268C0012E6176255EFA6FB7D67D6A2A3';

$public_key="-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFxkd8seAAOCAQ8AMIIBCgKCAQEAw5jrOBbKzur2ED
I/6zKwjFa2NKV7mgQH0N1lNw74bq+ce4qY7nTmUBz5SKIXtjENDtguAfHl9qX2ZW
52plZIaDthwa9YgdOu5+pJNKcO8AeCFbF9AURkQgie9lCBmZWCiLtDyCczIsRTPj
TztlpqUveypJCOp3jCHLpE8PGJ2LUHgQyGx1Pc+s/PQs4Z3qyVtxWvFy5ugjXgCL
0IqXWQ4cLCUHA6+FAEBqIRZGATWBhKOafxbSiTpRQiXrLq5kVea/KXYFG9Mva0QL
QyjVJZsKNC6VK1VGRArMr2KQK69pBNiy+yQqCJw6A2LBAkcERAREHoZITUcA/Ycx
AQIDAQAB
-----END PUBLIC KEY-----";

$verified = openssl_verify($data, $signed, $public_key, OPENSSL_ALGO_SHA1);
echo $verified;
?>

please help

5
  • Your code (above) yields "openssl_verify() [function.openssl-verify.html]: supplied key param cannot be coerced into a public key" Commented Feb 26, 2024 at 12:48
  • I generated public key from private key in openssl using command>rsa -in private.key -pubout -out publickey.key.Does this error mean the public key is not valid or the arguments supplied to openssl_verify is wrong? Commented Feb 26, 2024 at 14:06
  • Running the code returns 0 and there are no errors but its not verified Commented Feb 26, 2024 at 14:25
  • Do you have error_reporting(0); enabled? To debug this you might want to set that as error_reporting(E_ALL) ~ for me this clearly shows the error/warning mentioned above. If this is a fault with my openssl version or similar then I apologise for the false steer Commented Feb 26, 2024 at 19:25
  • Output is 0 and printing the error string gives error:0909006C:PEM routines:get_name:no start line error:04091077:rsa routines:int_rsa_verify:wrong signature length1 Commented Feb 28, 2024 at 13:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.