What am I doing wrong? Can't Verify a decoded signature

require ‘openssl’
require ‘base64’

data = ‘sometypeofdata’
signature = ‘coded-in-BASE64’
pem = File.read(“public.pem”)
decoded_signature=Base64.decode64(signature)
key = OpenSSL::PKey::RSA.new(pem)
verified = key.verify(OpenSSL::Digest::SHA1.new, decoded_signature,
data)

verified (always) returns false

The public key is in x509 / PEM format.

  1. I do not have a private key.
  2. I was given a public key.
  3. I was given a signature.
  4. The signature when properly verified and decoded should match the
    data.
  5. It does not.

What am I doing wrong? I have literally searched for more than 2 days
and I cannot find “any” documentation that properly explains how to
verify a vendor signature when given only an x509 / pem public key.

I am at my wits end.

I have also tried using this:

def verify_message(cert_file, data, signature)
public_key = OpenSSL::X509::Certificate.new(cert_file).public_key
return public_key.verify(OpenSSL::Digest::SHA1.new,
ActiveSupport::Base64.decode64(signature), data)
end

But this returns:

OpenSSL::X509::CertificateError
nested asn1 error

I created 4 methods for verifying and all 4 don’t work:

All of the x509 versions return a nested asn1 error and the other two
non-x509 versions return false with no errors.

There was nothing wrong with my code, thankfully. Rails automatically
decodes all URLs when it builds the params. The signature being
verified kept all of the params encoded.

Here is the working code in its entirety for anyone that wants an
example: