xref: /aosp_15_r20/external/tink/java_src/examples/mac/README.md (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1# Java MAC example
2
3This example shows how to check the integrity of data with Tink 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
12tinkey 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
20```shell
21git clone https://github.com/google/tink
22cd tink/examples/java_src
23bazel build ...
24
25echo "some data" > data.txt
26touch mac_file.txt
27
28./bazel-bin/mac/mac_example compute \
29    ./mac/mac_test_keyset.json data.txt mac_file.txt
30
31./bazel-bin/mac/mac_example verify \
32    ./mac/mac_test_keyset.json data.txt mac_file.txt
33```
34