Hello, I have a webservice that's taking in parameters via CGI. If one of those parameters has a special character (& for example), it gets sent in as %26. If I immediately print out the contents of param('data'), it prints to the screen with &, not %26. This is causing me a problem because I am calculating an hmac_sha512_hex value to verify that the input is getting received as sent. On the JavaScript side I set each parameter with encodeURIComponent(), which is how it's getting %26, then I read all of those to create the hash. On the Perl side, it's calculating it with the &, instead of %26. Is there a way to access the true raw input? I only need it to validate this one part - that the hash_hmac from PHP matches the hmac_sha512_hex from Perl. Here's the basic of the Perl script for this portion:
my $raw_data = uri_unescape $query->param('data'); my $api_key = uri_unescape $query->param('api_key'); $sth = $user_dbh->prepare($get_secret_key); $sth->execute($user_id); my ($secret_key) = $sth->fetchrow_array() and $sth->finish(); ... if($api_key eq hmac_sha512_hex($raw_data.$xyz.$abc,$secret_key)) { $auth_services{$service}->(); }else{ $status_ref->{'status'} = "FAIL"; $status_ref->{'status_cd'} = "F"; $status_ref->{'message'} = "Login details unable t +o be confirmed"; $status_ref->{'response_cd'} = "401"; }
Thanks!

In reply to CGI Input with Escaped Characters by hoyt

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.