xref: /aosp_15_r20/external/tink/python/examples/hybrid/README.md (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1# Python hybrid encryption example
2
3This example shows how to encrypt data with Tink using hybrid encryption.
4
5It demonstrates the basic steps of using Tink, namely loading key material,
6obtaining a primitive, and using the primitive to do crypto.
7
8The key material was generated with Tinkey:
9
10```shell
11$ tinkey create-keyset \
12    --key-template DHKEM_X25519_HKDF_SHA256_HKDF_SHA256_AES_256_GCM \
13    --out-format JSON --out hybrid_test_private_keyset.json
14
15$ tinkey create-public-keyset --in hybrid_test_private_keyset.json \
16    --in-format JSON --out-format JSON --out hybrid_test_public_keyset.json
17```
18
19## Build and Run
20
21### Bazel
22
23```shell
24$ git clone https://github.com/google/tink
25$ cd tink/python/examples
26$ bazel build ...
27```
28
29You can then encrypt a file:
30
31```shell
32$ echo "some data" > testdata.txt
33$ ./bazel-bin/hybrid/hybrid --mode encrypt \
34    --keyset_path ./hybrid/hybrid_test_public_keyset.json \
35    --input_path testdata.txt --output_path testdata.txt.encrypted
36```
37
38Or decrypt the file with:
39
40```shell
41$ ./bazel-bin/hybrid/hybrid --mode decrypt \
42    --keyset_path ./hybrid/hybrid_test_private_keyset.json \
43    --input_path testdata.txt.encrypted --output_path testdata.txt.decrypted
44$ diff testdata.txt testdata.txt.decrypted
45```
46