In case this helps, I ran the Go code

package main import ( "fmt" "encoding/hex" "encoding/base64" "crypto/hmac" "crypto/sha256" ) func main() { x := makeHmac("abcdef","1234567890") fmt.Printf("%s\n", x) } func makeHmac(data string, key string) string { byteKey, _ := hex.DecodeString(key) byteData := []byte(data) sig := hmac.New(sha256.New, byteKey) sig.Write([]byte(byteData)) return base64.StdEncoding.EncodeToString(sig.Sum(nil)) }

and the result was

1CBMzMydzanzzzHwnZKJEswN1jqvKZiI3fwBw81t1f4=

Running this perl

#!perl use strict; use Digest::SHA qw( hmac_sha256_base64 ); my $digest = hmac_sha256_base64("abcdef", pack "H*",'1234567890'); print $digest;

gave the same but without the padding

1CBMzMydzanzzzHwnZKJEswN1jqvKZiI3fwBw81t1f4
poj

1. updated with perl code

2. updated with full example code below both giving same result
GET\n08 Apr 2015 21:37:33 GMT\nd6468df6c1e8419fb5ec50f62be9a28b\n/xxxxxxxxxxxx/xxxxxxx/api/v1/users/xxxxx/factors
ApplicationID:2LIG2VOfl6swsD6rwRxBHW64dF6WK0vOO+b+VO/UbTk=
Basic :QXBwbGljYXRpb25JRDoyTElHMlZPZmw2c3dzRDZyd1J4QkhXNjRkRjZXSzB2T08rYitWTy9VYlRrPQ==

#!perl use strict; use Digest::SHA qw( hmac_sha256_base64 ); use MIME::Base64; my $datestring = '08 Apr 2015 21:37:33 GMT'; my $method = 'GET'; my $appid = 'd6468df6c1e8419fb5ec50f62be9a28b'; my $appkey = '15c7a6e1a5bd73500db29dffd0e19b6c6228b044c64348a6f5d6d470 +c54fc208'; my $path = '/xxxxxxxxxxxx/xxxxxxx/api/v1/users/xxxxx/factors'; # build the hash string my $step1 = "$method\\n$datestring\\n$appid\\n$path"; print "$step1\n"; # hmac, base64 and add padding my $step3 = hmac_sha256_base64($step1, pack "H*",$appkey); while (length($step3) % 4) { $step3 .= '='; } my $step4 = 'ApplicationID:'.$step3; print "$step4\n"; my $step6 = "Basic :".encode_base64($step4,''); print "$step6\n";
// GO code package main import ( "fmt" "encoding/hex" "encoding/base64" "crypto/hmac" "crypto/sha256" ) func main() { datestring := "08 Apr 2015 21:37:33 GMT" appid := "d6468df6c1e8419fb5ec50f62be9a28b" appkey:= "15c7a6e1a5bd73500db29dffd0e19b6c6228b044c64348a6f5d6d470c5 +4fc208" path := "/xxxxxxxxxxxx/xxxxxxx/api/v1/users/xxxxx/factors" step1 := "GET\\n"+datestring+"\\n"+appid+"\\n"+path fmt.Printf("%s\n",step1) step4 := "ApplicationID:" + makeHmac( step1, appkey ) fmt.Printf("%s\n",step4) step6 := "Basic :" + base64.StdEncoding.EncodeToString([]byte(step4) +) fmt.Printf("%s\n", step6) } func makeHmac(data string, key string) string { byteKey, _ := hex.DecodeString(key) byteData := []byte(data) sig := hmac.New(sha256.New, byteKey) sig.Write([]byte(byteData)) return base64.StdEncoding.EncodeToString(sig.Sum(nil)) }

In reply to Re^5: HMAC Sha256 Help! (updated) by poj
in thread HMAC Sha256 Help! by ribble

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.