tree: 8cc12e09f5b0856498acb27a569df615cd9d7e63 [path history] [tgz]
  1. BUILD.bazel
  2. mac.py
  3. mac_basic.py
  4. mac_basic_test.py
  5. mac_test.sh
  6. mac_test_keyset.json
  7. README.md
python/examples/mac/README.md

Python MAC example

This example shows how to check the integrity of data using Message Authentication Code (MAC).

It demonstrates the basic steps of using Tink, namely loading key material, obtaining a primitive, and using the primitive to do crypto.

The key material was generated with:

$ tinkey create-keyset --key-template HMAC_SHA256_256BITTAG --out-format JSON \
    --out mac_test_keyset.json

Build and Run

Bazel

Build the examples:

$ git clone https://github.com/google/tink
$ cd tink/python/examples
$ bazel build ...

Compute a MAC:

$ echo "some data" > data.txt
$ touch mac_file.txt
$ ./bazel-bin/mac/mac --mode compute \
    --keyset_path ./mac/mac_test_keyset.json \
    --data_path data.txt --mac_path mac_file.txt

Verify a MAC:

$ ./bazel-bin/mac/mac --mode verify \
    --keyset_path ./mac/mac_test_keyset.json \
    --data_path data.txt --mac_path mac_file.txt