openssl_sign() & openssl_verify() discrepancy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have run into a problem that I am altogether unfamiliar with.

A scenario. I retrieve a users private key from a database.

I then use the openssl_pkey_get_private() function to load it as a resource object and proceed to call the openssl_sign() function to obtain a digital signature of a string.

No problem, I get a valid signature which I then base64 encode and store in a database.

Now lets say a couple of days from now I load up the public key which corresponds to the private key which was used to originally sign the data to verify it and it does not work.

The kicker is if I perform the very same routine without saving the signature and attempting to verify it it works without problems.

Example script:

/* this part works */
$id = openssl_pkey_get_private($key, $pass);
openssl_sign($unsigned, $signed, $id);

$id = openssl_pkey_get_public($pub);
openssl_verify($unsigned, $signed, $id);

/* this doesn't (here I use the existing signature instead of generating a new one) */
$id = openssl_pkey_get_public($pub);
openssl_verify($unsigned, $signature, $id);

/* below here is all of the existing variables the above uses */

$unsigned = "w9A5Tt8JA/GVBn89WwpvXnnVsHvyWbEDu5GdX36m+ZQ=:ek4L55qc/VKAmiYdlIQhow==:ek4L55qc/VKAmiYdlIQhow==:6IraS+ArqK+/Yc472tfFqmhk5VdIACUQPCR7+kbLoAEldjejS/P1cSa8EMHxcV2s:50dt57IoKeQZ7eiwoILMR3E91MtbCgt+xVn483+9J1cNzBQGll02Qj40RVhNM/Rh:qEFBUlZzNYZNb7nksj8Fhd8Du52RVDjMBwoT/O0tdzKGfGVOeK2xrpuq1OdoAo2CN63U+Fra4zcfkzwkD3QxDA==:1337713224"

$pass = "$2a$07$31a9f929d102f5f0374deuu.cfoTJbmZtGKk92CuAOP63XaRUAVIW";

$signature = "h+SdcyxuQ9kpb2CXZRA/grJjlYj+drlOH2f7Ifsnt5A8dSj9lkMYU11rtjT9sdaEhf3rvoIl9JUMvkzc6dJ4DMypqgGniqbesbK6yf30FmPd0an+bTyIpeQFasmUwxtB1y6wBjIENEzEDTyb6QHPTAZg6ep2m/NjZFfUn/iiDOnDt71KQD1whouwtRZ0+UcDfPvtLQ3bAGw9C5ThDoIHRlg1kzVLrq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AW4bNDsnfUnP
YFQVdFco03Pbz8vejc0SVSC8l2lw+ZSkMYDzDmhv09Uk1zh1kc/ACOU0AoofEaUM
2eyekwcQiVwzKksGjW70eOuI2QtgpIwuvQSS/BAcymYKkxJZVxUMPCwdBwY+Pyo+
+lD4yGeki0E7x72uQy0bzulxa6iXhQOYFQEcShxyJEF6YN/R/XSIQBLTi9biWvGg
6QIDAQAB
-----END PUBLIC KEY-----";



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux