Name Date Size #Lines LOC

..--

BUILD.bazelH A D25-Apr-20251.5 KiB7162

README.mdH A D25-Apr-2025948 4532

mac.pyH A D25-Apr-20252.8 KiB9559

mac_basic.pyH A D25-Apr-20252.5 KiB6628

mac_basic_test.pyH A D25-Apr-2025798 278

mac_test.shH A D25-Apr-20253.8 KiB13361

mac_test_keyset.jsonH A D25-Apr-2025387 1413

README.md

1# Python MAC example
2
3This example shows how to check the integrity of data using Message
4Authentication Code (MAC).
5
6It demonstrates the basic steps of using Tink, namely loading key material,
7obtaining a primitive, and using the primitive to do crypto.
8
9The key material was generated with:
10
11```shell
12$ tinkey create-keyset --key-template HMAC_SHA256_256BITTAG --out-format JSON \
13    --out mac_test_keyset.json
14```
15
16## Build and Run
17
18### Bazel
19
20Build the examples:
21
22```shell
23$ git clone https://github.com/google/tink
24$ cd tink/python/examples
25$ bazel build ...
26```
27
28Compute a MAC:
29
30```shell
31$ echo "some data" > data.txt
32$ touch mac_file.txt
33$ ./bazel-bin/mac/mac --mode compute \
34    --keyset_path ./mac/mac_test_keyset.json \
35    --data_path data.txt --mac_path mac_file.txt
36```
37
38Verify a MAC:
39
40```shell
41$ ./bazel-bin/mac/mac --mode verify \
42    --keyset_path ./mac/mac_test_keyset.json \
43    --data_path data.txt --mac_path mac_file.txt
44```
45