How to convert a PHP function $rsa->verifyto node? I used the cryptography verification function as follows:
const crypto = require('crypto');
const verify = crypto.createVerify('RSA-SHA256');
verify.update('some data to sign');
const public_key = getPublicKeySomehow();
const signature = getSignatureToVerify();
console.log(verify.verify(public_key, signature));
But it always returns false. When I run my data and signature through php, it returns true! Any idea what I can do wrong?
The php check function is as follows:
function verify($message, $signature)
{
if (empty($this->modulus) || empty($this->exponent)) {
return false;
}
switch ($this->signatureMode) {
case CRYPT_RSA_SIGNATURE_PKCS1:
return $this->_rsassa_pkcs1_v1_5_verify($message, $signature);
default:
return $this->_rsassa_pss_verify($message, $signature);
}
}
It seems that CRYPT_RSA_SIGNATURE_PKCS1 is being used. How to use it in node?
function _rsassa_pss_verify($m, $s)
{
if (strlen($s) != $this->k) {
user_error('Invalid signature');
return false;
}
$modBits = 8 * $this->k;
$s2 = $this->_os2ip($s);
$m2 = $this->_rsavp1($s2);
if ($m2 === false) {
user_error('Invalid signature');
return false;
}
$em = $this->_i2osp($m2, $modBits >> 3);
if ($em === false) {
user_error('Invalid signature');
return false;
}
return $this->_emsa_pss_verify($m, $em, $modBits - 1);
}
source
share