rjschwei has asked for the wisdom of the Perl Monks concerning the following question:
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:How would I do this in Perl?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)
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.
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....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' );
The openssl dgst command does not handle a cert and extracting the public key didn't lead to the desired result:
The verification with openssl fails, but it should be valid and is valid with the Python code above. Help is much appreciated.openssl x509 -in cert.pem -pubkey >& pubkey.txt openssl dgst -sha256 -verify pubkey.txt -signature signature.txt myDat +a.txt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Verify signed data
by tobyink (Canon) on May 23, 2014 at 02:31 UTC | |
by rjschwei (Novice) on May 23, 2014 at 17:04 UTC | |
|
Re: Verify signed data
by Anonymous Monk on May 23, 2014 at 01:59 UTC | |
|
Re: Verify signed data
by rjschwei (Novice) on May 23, 2014 at 17:09 UTC |