1Crypt::Mac::HMAC(3)   User Contributed Perl Documentation  Crypt::Mac::HMAC(3)
2
3
4

NAME

6       Crypt::Mac::HMAC - Message authentication code HMAC
7

SYNOPSIS

9          ### Functional interface:
10          use Crypt::Mac::HMAC qw( hmac hmac_hex );
11
12          # calculate MAC from string/buffer
13          $hmac_raw  = hmac('SHA256', $key, 'data buffer');
14          $hmac_hex  = hmac_hex('SHA256', $key, 'data buffer');
15          $hmac_b64  = hmac_b64('SHA256', $key, 'data buffer');
16          $hmac_b64u = hmac_b64u('SHA256', $key, 'data buffer');
17
18          ### OO interface:
19          use Crypt::Mac::HMAC;
20
21          $d = Crypt::Mac::HMAC->new('SHA256', $key);
22          $d->add('any data');
23          $d->addfile('filename.dat');
24          $d->addfile(*FILEHANDLE);
25          $result_raw  = $d->mac;     # raw bytes
26          $result_hex  = $d->hexmac;  # hexadecimal form
27          $result_b64  = $d->b64mac;  # Base64 form
28          $result_b64u = $d->b64umac; # Base64 URL Safe form
29

DESCRIPTION

31       Provides an interface to the HMAC message authentication code (MAC)
32       algorithm.
33

EXPORT

35       Nothing is exported by default.
36
37       You can export selected functions:
38
39         use Crypt::Mac::HMAC qw(hmac hmac_hex );
40
41       Or all of them at once:
42
43         use Crypt::Mac::HMAC ':all';
44

FUNCTIONS

46   hmac
47       Logically joins all arguments into a single string, and returns its
48       HMAC message authentication code encoded as a binary string.
49
50        $hmac_raw = hmac($hash_name, $key, 'data buffer');
51        #or
52        $hmac_raw = hmac($hash_name, $key, 'any data', 'more data', 'even more data');
53
54   hmac_hex
55       Logically joins all arguments into a single string, and returns its
56       HMAC message authentication code encoded as a hexadecimal string.
57
58        $hmac_hex = hmac_hex($hash_name, $key, 'data buffer');
59        #or
60        $hmac_hex = hmac_hex($hash_name, $key, 'any data', 'more data', 'even more data');
61
62   hmac_b64
63       Logically joins all arguments into a single string, and returns its
64       HMAC message authentication code encoded as a Base64 string.
65
66        $hmac_b64 = hmac_b64($hash_name, $key, 'data buffer');
67        #or
68        $hmac_b64 = hmac_b64($hash_name, $key, 'any data', 'more data', 'even more data');
69
70   hmac_b64u
71       Logically joins all arguments into a single string, and returns its
72       HMAC message authentication code encoded as a Base64 URL Safe string
73       (see RFC 4648 section 5).
74
75        $hmac_b64url = hmac_b64u($hash_name, $key, 'data buffer');
76        #or
77        $hmac_b64url = hmac_b64u($hash_name, $key, 'any data', 'more data', 'even more data');
78

METHODS

80   new
81        $d = Crypt::Mac::HMAC->new($hash_name, $key);
82
83   clone
84        $d->clone();
85
86   reset
87        $d->reset();
88
89   add
90        $d->add('any data');
91        #or
92        $d->add('any data', 'more data', 'even more data');
93
94   addfile
95        $d->addfile('filename.dat');
96        #or
97        $d->addfile(*FILEHANDLE);
98
99   mac
100        $result_raw = $d->mac();
101
102   hexmac
103        $result_hex = $d->hexmac();
104
105   b64mac
106        $result_b64 = $d->b64mac();
107
108   b64umac
109        $result_b64url = $d->b64umac();
110

SEE ALSO

112       ·   CryptX
113
114       ·   <https://en.wikipedia.org/wiki/Hmac>
115
116       ·   <https://tools.ietf.org/html/rfc2104>
117
118
119
120perl v5.32.1                      2021-03-30               Crypt::Mac::HMAC(3)
Impressum