30. #!/usr/bin/perl
use strict;
use warnings;
use Digest::SHA qw(hmac_sha256_hex);
use Perl6::Say;
our $hmac_key = "common_secret";
sub format_keyval {
my %pairs = @_;
join "n" => map { $_ . ':' . $pairs{$_} }
keys %pairs;
}
sub sig {
my %pairs = @_;
my $keyval = format_keyval(%pairs);
hmac_sha256_hex($keyval,
$hmac_key);
}
say sig( foo => "abc", bar => "xyz" );
89b7f51ec9b76e97d5a179f313af38e6cc8b5cb086
0e266caf6847ded05428ce