Greetings Monks,
Apologize for the re-post here but I did not receive a response on the previous thread. I need to verify the signature of a message sent to me (e.g.: Web token). The message is colon separated, with the ending being the signature. I have the public key stored as a binary file. I am trying to use Crypt::OpenPGP to validate this signature. I have never worked on something like this before, so that is why I am reaching out for some help. In the code below, I have the signature and the message in separate files. Ideally, the message (including the signature after the last colon) would be passed to me and I would parse it to get the signature. This is what I have so far:

#!/usr/bin/perl -w use strict; use Crypt::OpenPGP; #Public key stored in binary file my $pbkey = 'public.bin.key'; #This is how I would get message, which includes the signature #my $message = 'colon_separated_values'; #my $signature = 'parsed_string_from_message'; #Tried having the message and signature in separate files my $signature = 'sigFile.txt'; my $message = 'message.txt'; my $pubring = Crypt::OpenPGP::KeyRing->new(Filename => $pbkey) || die +"Pubring Failed: ",$pbkey->errstr; my $pgp = Crypt::OpenPGP->new(PubRing => $pubring) or die "Can't find +public key"; my $result = $pgp->verify( SigFile => $signature, Data => [ $message ] ) || die "Verification Failed: ",$pgp->errstr; if ($result) { print "Verified, signing key: $result\n"; } else { print "Bad signature!\n"; }

This outputs: "Verification Failed: SigFile contents are strange"
Not sure if I am on the right track here so would definitely appreciate any guidance you may offer. Thanks in advance.


In reply to Verify Digital Signature by perlPractioner

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.