I'm having problems with hash encoding in Perl. I've narrowed it down to the following code which seems to be giving me the wrong result

#!/usr/bin/perl use warnings; use strict; use Digest::SHA qw(sha256 sha256_hex); my $digest=sha256_hex("138539083512345apiKeyDEMO","apiSecretDEMO" ); print "Digest=$digest\n"; # correct answer is: #696E087F4B1902AA58D35E75B4600580D70A92ED68B23379373117FB3FE3064A # my code generates: #ea645ae07e04289f3fe14c81af54f7da9cae1114fe2bb9efbb6b383ef276434b

I've included what the answer should be at the bottom. I've checked the answer at http://hash.online-convert.com/sha256-generator and it confirms the correct figure. Why is my code generating the wrong answer?


In reply to Problems with HMAC SHA-256 by agnome

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.