xref: /aosp_15_r20/external/tink/python/examples/deterministic_aead/README.md (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1# Python Deterministic AEAD example
2
3This example shows how to encrypt files with Tink using Deterministic
4Authenticated Encryption with Associated Data (Deterministic AEAD).
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 Tinkey:
10
11```shell
12$ tinkey create-keyset --key-template AES256_SIV --out-format JSON \
13    --out deterministic_aead_test_keyset.json
14```
15
16## Build and run
17
18### Bazel
19
20```shell
21$ git clone https://github.com/google/tink
22$ cd tink/python/examples
23$ bazel build ...
24```
25
26You can then encrypt a file
27
28```shell
29$ echo "some data" > testdata.txt
30$ ./bazel-bin/deterministic_aead/deterministic_aead --mode encrypt \
31    --keyset_path deterministic_aead/deterministic_aead_test_keyset.json \
32    --input_path testdata.txt --output_path testdata.txt.encrypted
33```
34
35or decrypt the file with
36
37```shell
38$ ./bazel-bin/deterministic_aead/deterministic_aead --mode decrypt \
39    --keyset_path deterministic_aead/deterministic_aead_test_keyset.json \
40    --input_path testdata.txt.encrypted --output_path testdata.txt.decrypted
41$ diff testdata.txt testdata.txt.decrypted
42```
43