Hi,

Loads of Google searches and lots of reading have not led me to the desired result.

I have data that was signed by someone else. I also have the signature and I have a certificate. I want to verify in Perl that the data has not been fiddled with.

In Python this works for me as follows:
from M2Crypto import X509 def verify_data(data, signature, cert): rawsig = signature..decode('base64') x509 = X509.load_cert_string(cert) pubkey = x509.get_pubkey() pubkey.reset_context(md='sha256') pubkey.verify_init() pubkey.verify_update(data) return pubkey.verify_final(rawsig)
How would I do this in Perl?

All the X509 things I have found appear to have options to deal with the certificate itself, but I haven't found the next step, i.e.

my $x509 = Crypt::OpenSSL::X509->new_from_file('cert.pm'); my $pubkey = $x509->pubkey(); my $signature = read_file('signature.txt' , binmode => ':raw' ); my $data = read_file('data.txt' , binmode => ':raw' );
But what happens next, as in Python I'd now like to call some methods that verify the signature and data against the public key....

The openssl dgst command does not handle a cert and extracting the public key didn't lead to the desired result:

openssl x509 -in cert.pem -pubkey >& pubkey.txt openssl dgst -sha256 -verify pubkey.txt -signature signature.txt myDat +a.txt
The verification with openssl fails, but it should be valid and is valid with the Python code above. Help is much appreciated.

In reply to Verify signed data by rjschwei

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.