鉴于php验证签名对于使用公钥id的指定数据是正确的。 什么是红宝石等同物?

Given the following PHP method below to verify that a signature is correct for specified data using the public key associated with pub_key_id. See PHP openssl_verify. What is the ruby equivalent?. I have the following PHP code snippet:

$data = $_POST['posted_data'];
$signature = base64_decode($_POST['signature']);
$public_key_id = openssl_pkey_get_public($public_key);
$verified = openssl_verify($data, $signature, $public_key_id);
openssl_free_key($key_id);

if($verified == 1)
{
    echo "VERIFIED";
}
else if ($verified == 0)
{
    echo "VERIFICATION FAILED";
}
else if ($verified < 0)
{
    echo "ERROR";
}

I am trying to write the ruby equivalent of the program? Thanks in advance.

I believe this should work for you:

signature = Base64.decode64(params["signature"])
sha256    = OpenSSL::Digest::SHA256.new
pub_key   = OpenSSL::PKey::RSA.new(public_key).public_key
pub_key.verify(sha256, signature, params["data"])

This will return true if the they match, false otherwise